Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

What Does ISNULL Mean in this CASE Statement?

I'm trying to understand the logic behind this CASE Statement:

 CASE 
            WHEN view_txn.type = 'C'
            THEN claimid + ' Charge - ' + ISNULL(cptdesc,'')
            WHEN view_txn.type = 'A'
            THEN claimid + ' Adjustment - ' + ISNULL(payerdesc,'')
            WHEN view_txn.type = 'P' and payer = 'I'
            THEN claimid + ' Payment - ' + ISNULL(payerdesc,'')
            WHEN paymentmethod = 'DS'
            THEN claimid + ' Discount - ' + ISNULL(payerdesc,'')
            WHEN paymentmethod = 'RV'
            THEN claimid + ' Payment Reversal - ' + ISNULL(payerdesc,'')
            WHEN paymentmethod = 'RF'
            THEN claimid + ' Refund - ' + ISNULL(payerdesc,'')
            WHEN paymentmethod = 'AJ'
            THEN claimid + ' Adjustment - ' + ISNULL(payerdesc,'')
            ELSE 'Payment - ' + ISNULL(payerdesc,'')
            END as description,

Open in new window


It seems like "description" is going to be a conjugated string that will consist of the claim id plus a keyword (Adjustment, Refund, etc) and...

What does ISNULL mean?
SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In your query if the column value is NULL it is replaced by blank value that is '' <<Single Quotes>>

ISNULL(cptdesc,'')   -- now if the value of cptdesc is NULL then ''.

Now why they are doing is because they have to concat.

NULL + 'a'  Gives NULL thats why. [SQL Server Internally works like this.]

Hope it helps.
Avatar of Sean Stuber
Sean Stuber

Pawan Kumar Khowal, please read the thread prior to posting.

Everything you posted was already in the very first post above and expanded on in followup posts.
This happens if you dont refresh the page before posting. @Author - Ignore my comment.
@Pawan - Looking at the timestamps it appears you had the question open for almost 40 minutes before posting your comment, which seems unlikely.
@Jim (sometimes I leave the question open while I work on an answer.  I try and refresh periodically so I don't waste my time, but I've accidentally done the same)
Dustin - That's also why I type real fast on easy questions, as in this case in the time it took me to come up with my witty Ted Nugent and Purple Dinosaur analogies two experts posted correct answers.
Avatar of Bruce Gust

ASKER

Thank you!
I see that!  You could probably speed that up with a pop culture reference generating SP in your test database.