Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

Select Multiple Rows into Multiple Columns

$
0
0

I have a table called DiagnosisList, which contains following fields and sample data. I need to switch the DiagnosisCodes, DiagnosisDescriptions and DiagCodeTypes into one row per Identifier.


I was trying to use the following case when statement, but that causes NULL values when there is more than one result for an Identifier. In the example below, I need the data in row 6 to move up to row 5:

select Identifier, case when Dx# = '1' then DiagnosisCode end as DxCode1,
case when Dx# = '1' then DiagnosisDescription end as DxDescription1,
case when Dx# = '1' then DiagCodeType end as DxType1,
case when Dx# = '2' then DiagnosisCode end as DxCode2,
case when Dx# = '2' then DiagnosisDescription end as DxDescription2,
case when Dx# = '2' then DiagCodeType end as DxType2
from DiagnosisList


Any assistance would be greatly appreciated!


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>