Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Case When Resulting in Null Expand / Collapse
Author
Message
Posted Wednesday, July 31, 2013 10:39 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 2:06 PM
Points: 27, Visits: 143
Hi All,

I just need clarification of why a field for some records would result in a null value for a query like the following, particularly for the StatusCd field. I believe it would be when none of the whens apply? Please advise:

SELECT InternalICN
, EncounterLineNum
, STSDate StatusDt
, case HeaderStatus
when 'F0' then 3 -- PAY
when 'VE' then 3
when 'F2' then 4 -- DENY
when 'P2' then 9 -- SUSPEND
when 'PC' then 10
end AS StatusCd
, case HeaderStatus
when 'VE' then 1500
else 600
end AS StatusReasonCd
, isnull(drec.dpwicn,'') as DPWICN
FROM T277.Enc277_2200D drec join
T277.EncounterTrackingTemp et on et.InternalICN = drec.TraceNo
where et.StatusCd <> 2

Thanks!
Post #1479596
Posted Wednesday, July 31, 2013 11:12 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 4:29 PM
Points: 12,741, Visits: 31,053
you are correct; you are testing for five specific values in your CASE, and there's no explicit ELSE in it to handle other values, and the built in logic structure of the case returns NULL for items that don't match the tests in the CASE when no explicit ELSE is provided.

Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1479610
Posted Wednesday, July 31, 2013 11:53 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 2:06 PM
Points: 27, Visits: 143
Thanks, Lowell. Your response was helpful...I know it's something that may have been obvious, but I just wanted to verify.
Post #1479627
Posted Wednesday, July 31, 2013 12:16 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 4:29 PM
Points: 12,741, Visits: 31,053
Sanity Checks are always a good thing! glad i could help!

Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1479636
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse