Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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: Thursday, August 14, 2014 2:30 PM
Points: 38, Visits: 173
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: Today @ 1:10 PM
Points: 14,412, Visits: 37,721
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
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: Thursday, August 14, 2014 2:30 PM
Points: 38, Visits: 173
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: Today @ 1:10 PM
Points: 14,412, Visits: 37,721
Sanity Checks are always a good thing! glad i could help!

Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Post #1479636
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse