Question : Case statment

I was trying to do a case statement but I am unsure if what I am trying to do can be handled by a case statment. I want to select shipnum if it does not equal 0 and custnum if it does equal 0. Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
select top 1000 

orderno,
CASE shipnum 
when 0 then custnum
when <>0 then shipno
END  as shipto  

from CMS

Answer : Case statment

This is an alternative form, just FYI

select top 1000
orderno,
coalesce(nullif(shipnum,0),custnum) as shipto  
from CMS

If shipnum is 0, it is converted to null, which the coalesce then picks up and substitutes for custnum.
Bonus is that if shipnum is NOT 0 but IS NULL, it will also use custnum.
Random Solutions  
 
programming4us programming4us