Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
scottstown
Starting Member
10 Posts |
Posted - 2011-07-25 : 12:53:38
|
| The following statement,Select PatientID, cttest, XAtest, dxtestFROM (SELECT PatientID,case when Modality = 'CT' THEN 'CT' end as CTtest,case when Modality = 'XA' THEN 'XA' end as XAtest,case when Modality = 'DX' THEN 'DX' end as DXtestFROM localdbviewWHERE patientid = 1482815)AS taGives me,1482815 NULL NULL DX1482815 CT NULL NULLHow would I go about combining the two rows in the example into one row, grouped by PatientID. Thank you,Scott |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-07-25 : 12:57:33
|
| [code]SELECT PatientID,MAX(case when Modality = 'CT' THEN 'CT' end) as CTtest,MAX(case when Modality = 'XA' THEN 'XA' end) as XAtest,MAX(case when Modality = 'DX' THEN 'DX' end) as DXtestFROM localdbviewGROUP BY PatientID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
scottstown
Starting Member
10 Posts |
Posted - 2011-07-25 : 13:25:50
|
| Wow, thank you visakh16! I thought that MAX could only be used for numbers. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-07-25 : 13:45:27
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|