Solved

What Does ISNULL Mean in this CASE Statement?

Posted on 2016-11-01
11
32 Views
Last Modified: 2016-11-01
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?
0
Comment
Question by:brucegust
  • 3
  • 2
  • 2
  • +3
11 Comments
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 125 total points
ID: 41868717
if the first parameter is null, then replace it with an empty string.

otherwise, when you did the concatenation, the entire result would be a null.

'x' + null  = null

'x' + '' = 'x'
0
 
LVL 4

Assisted Solution

by:Steven Kribbe
Steven Kribbe earned 125 total points
ID: 41868718
ISNULL (exp1, exp2) returns expr if exp1 is null
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 250 total points
ID: 41868719
>What does ISNULL mean?
Pick the first value that is a non-NULL.

ISNULL(NULL, 'banana') will return 'banana'.
ISNULL('Ted Nugent', NULL) will return 'Ted Nugent'.
ISNULL(42, 'Purple Dinosaur') will return 42.

It's a quick and dirty way to replace NULL values with something else in a SELECT clause.
To do this with more than two values use COALESCE.
0
 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
ID: 41868786
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.
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 41868821
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.
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 17

Expert Comment

by:Pawan Kumar Khowal
ID: 41868858
This happens if you dont refresh the page before posting. @Author - Ignore my comment.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41868884
@Pawan - Looking at the timestamps it appears you had the question open for almost 40 minutes before posting your comment, which seems unlikely.
0
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41868988
@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)
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41868997
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.
0
 

Author Closing Comment

by:brucegust
ID: 41869006
Thank you!
0
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41869007
I see that!  You could probably speed that up with a pop culture reference generating SP in your test database.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now