Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Mannga
Yak Posting Veteran
70 Posts |
Posted - 2002-11-05 : 07:01:55
|
| Hi All,Small problem here which I think will be relatively simple to answer.I have a query and in part of it I have the followingCASE ISNULL(PT.pt_PreviousDiagnosis,3) WHEN 'Y' THEN 1 WHEN 'N' THEN 2 WHEN 'U' THEN 3Which I take to say if PT.pt_PreviousDiagnosis Is NUll then make it 3 and go through the CASE statement. But it does not do this. I am still getting NULL's?Thanks,Gavin |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2002-11-05 : 07:09:20
|
quote: Hi All,Small problem here which I think will be relatively simple to answer.I have a query and in part of it I have the followingCASE ISNULL(PT.pt_PreviousDiagnosis,3) WHEN 'Y' THEN 1 WHEN 'N' THEN 2 WHEN 'U' THEN 3Which I take to say if PT.pt_PreviousDiagnosis Is NUll then make it 3 and go through the CASE statement. But it does not do this. I am still getting NULL's?Thanks,Gavin
Because you're not testing for nulls. Your case statement is incomplete, or back to front...CASE isnull (PT.pt_PreviousDiagnosis,3) when 1 then 'Y' when 2 then 'N' when 3 then 'U'else 'something else' -- to catch nullsend or as you had itCASE ISNULL(PT.pt_PreviousDiagnosis,3) WHEN 'Y' THEN 1 WHEN 'N' THEN 2 WHEN 'U' THEN 3 ELSE 'some other value'end |
 |
|
|
LarsG
Constraint Violating Yak Guru
284 Posts |
Posted - 2002-11-05 : 07:09:50
|
| As none of the conditions in the case matches the value 3 the result of the case expression is null.CASE PT.pt_PreviousDiagnosis WHEN 'Y' THEN 1 WHEN 'N' THEN 2 else 3 |
 |
|
|
Mannga
Yak Posting Veteran
70 Posts |
Posted - 2002-11-05 : 07:20:24
|
I cannot beleive I missed that Thanks it's working prefectly nowmr_mistThanks for the help and showing me that you can use Else statement in Case statements Cheers,Gavinquote: As none of the conditions in the case matches the value 3 the result of the case expression is null.CASE PT.pt_PreviousDiagnosis WHEN 'Y' THEN 1 WHEN 'N' THEN 2 else 3
|
 |
|
|
|
|
|