|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Wednesday, October 24, 2012 8:17 PM
Points: 1,588,
Visits: 247
|
|
Good question, I had to read it carefully.
http://brittcluff.blogspot.com/
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, June 06, 2013 4:06 PM
Points: 1,219,
Visits: 13,509
|
|
good question!!
rfr.ferrari DBA - SQL Server 2008 MCITP | MCTS
remember is live or suffer twice!
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 7:23 AM
Points: 1,355,
Visits: 436
|
|
stewartc-708166 (10/10/2011)
This is a good question, showing that care needs to be exercised when working with NULLs Ajay.Kedar (10/10/2011)
I tried and got wrong in first select case  But wanted to know that How can we chack null in this case then? As shown in the explanation, the way the CASE is structured will need to be changed somewhat, i.e. SELECT CASE WHEN COL1 IS NULL THEN 'Is Null' WHEN COL1 = '0' THEN 'Is Zero' WHEN COL1 = '1' THEN 'Is One' WHEN COL1 = '2' THEN 'Is Two' END FROM ( SELECT NULL AS Col1 UNION SELECT '0' AS Col1 UNION SELECT '1' AS Col1 UNION SELECT '2' AS Col1 ) TMP
This is the form that I always use nowadays, rarely are any of the select conditions that are simple value type check expressions.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Yesterday @ 1:46 PM
Points: 581,
Visits: 700
|
|
Great question.
Thanks,
Matt
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 5:11 AM
Points: 1,168,
Visits: 1,470
|
|
Nice one! I almost missed it, but my spidy sense told me to look at the question again. Thanks.
Please don't go. The drones need you. They look up to you.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 8:53 AM
Points: 2,499,
Visits: 2,200
|
|
Nice question - thanks
------------------------------- Posting Data Etiquette - Jeff Moden Smart way to ask a question
There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan I would never join a club that would allow me as a member - Groucho Marx
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 2:37 PM
Points: 8,978,
Visits: 8,538
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Tuesday, June 04, 2013 9:19 AM
Points: 2,058,
Visits: 934
|
|
I got an error when I executed the code - oh well
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:27 AM
Points: 1,384,
Visits: 4,881
|
|
Sean Lange (10/10/2011)[hrThis works except you can't differentiate between null and empty strings because your isnull will now treat them both the same. In some cases this is ok but in others it isn't.
If it matters then you can do something like
CASE IsNull(COL1,'avaluethatwillnotappearinthedata') WHEN 'avaluethatwillnotappearinthedata' THEN 'Is Null'
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 10:27 AM
Points: 1,384,
Visits: 4,881
|
|
Or:
SELECT CASE when Col1 is null then 'Is Null' else case col1 WHEN '0' THEN 'Is Zero' WHEN '1' THEN 'Is One' WHEN '2' THEN 'Is Two' END end FROM ( SELECT NULL AS Col1 UNION SELECT '0' AS Col1 UNION SELECT '1' AS Col1 UNION SELECT '2' AS Col1 ) TMP
|
|
|
|