Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

case problem 2

Status
Not open for further replies.

shannanl

IS-IT--Management
Apr 24, 2003
1,071
US
I am using the following. It returns "IT IS NOT NULL" no matter if there is a null value in the Disch_date field or not. What am I doing wrong?

Thanks in advance - Shannan

SELECT Admit_date, Disch_date,

CASE Disch_date
WHEN NULL THEN 'IT IS NULL'
ELSE 'IT IS NOT NULL'
END 'RESULTS'

FROM Pat_visit_T
 
You cannot test for null that way. Here's a method that will work.

Code:
[COLOR=blue]SELECT[/color] Admit_date, Disch_date,
 
  [COLOR=blue]CASE[/color] [COLOR=blue]When[/color] Disch_date [COLOR=blue]Is[/color] NULL
      [COLOR=blue]THEN[/color] [COLOR=red]'IT IS NULL'[/color]
      [COLOR=blue]ELSE[/color] [COLOR=red]'IT IS NOT NULL'[/color]
  [COLOR=blue]END[/color] [COLOR=red]'RESULTS'[/color]

[COLOR=blue]FROM[/color] Pat_visit_T

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
try this

Code:
[COLOR=blue]SELECT[/color] Admit_date, Disch_date,
 
  [COLOR=blue]CASE[/color] [COLOR=blue]WHEN[/color] Disch_date
       [COLOR=blue]IS[/color] NULL [COLOR=blue]THEN[/color] [COLOR=red]'IT IS NULL'[/color]
      [COLOR=blue]ELSE[/color] [COLOR=red]'IT IS NOT NULL'[/color]
  [COLOR=blue]END[/color] [COLOR=red]'RESULTS'[/color]

[COLOR=blue]FROM[/color] Pat_visit_T

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
Google Interview Questions





 
Thanks guys. I appreciate the quick response.

Shannan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top