Results 1 to 2 of 2

Thread: normalizing flat row of data

  1. #1
    Join Date
    Nov 2002
    Posts
    261

    normalizing flat row of data

    I have a view with patient data. It looks like below

    patid date pulmdc pulmstatus endodc endostatus
    100 4/1/05 10 Good null null
    100 5/1/05 10 Good 12 Poor

    I want to create sql which by each patient, by date, by these four fields ,get

    patid 4/1/05 pulmdc-10 pulmstatus-good
    patid 5/1/05 pulmdc-1 pulmstatus-good
    patid 5/1/05 endodc-12 endostatus-poor

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    use tempdb
    go

    create table test1 (patid int, date datetime, pulmdc int, pulmstatus varchar(100), endodc int, endostatus varchar(100))
    go
    insert into test1 select 100, '4/1/05', 10, 'Good', null, null
    insert into test1 select 100, '5/1/05', 1, 'Good', 12, 'Poor'
    go
    --select * from test1
    go
    select patid,date,pulmdc,MDC= 'Pulmdc -' +Convert(varchar(10),pulmdc), Status = 'Pulmstatus -' +Convert(varchar(10),pulmstatus) from test1 where pulmdc is not null
    union
    select patid,date,pulmdc,MDC= 'Endodc -' +Convert(varchar(10),endodc), Status = 'Endostatus -' +Convert(varchar(10),Endostatus) from test1 where endodc is not null

    go

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •