简体   繁体   中英

Single row with only values

How do I get a single row with only the values, I don't want to see the NULL values. I know I can make a Temp table from this query and then select MAX on the Temp table, but was wondering if there is a way to do it within this query.

Select VisitIDCode
,CASE WHEN (LeftJustifiedLabel) = 'Additional Intervention Information' Then (ValueText) Else Null End As 'Additional Intervention Information'
,CASE WHEN (LeftJustifiedLabel) = 'American Cancer Society Comment:' Then (ValueText) Else Null End As 'American Cancer Society Comment:'
,CASE WHEN (LeftJustifiedLabel) = 'Intevention' Then (ValueText) Else Null End As 'Intevention'
From #AssessmentFS
WHERE VisitIDCode = 123

Here is my current end result from the query above, I only added one Case field because it's to long for the others.

VisitIDCode  Additional Intervention Information  
123          Faxed referral to 877-428-2862
123          NULL
123          NULL      

You can aggregate (use max or min etc) in the same query.

select 
VisitIDCode
,MAX(CASE WHEN LeftJustifiedLabel = 'Additional Intervention Information' Then ValueText End) As 'Additional Intervention Information'
,MAX(CASE WHEN LeftJustifiedLabel = 'American Cancer Society Comment:' Then ValueText End) As 'American Cancer Society Comment:'
,MAX(CASE WHEN LeftJustifiedLabel = 'Intevention' Then ValueText End) As 'Intevention'
From #AssessmentFS
group by VisitIDCode

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM