开发者

SQL Server Inline CASE WHEN ISNULL and multiple checks

开发者 https://www.devze.com 2023-03-04 06:38 出处:网络
I have a column with some nulls. If that column is null, I want to condition output for it based on values in another column.

I have a column with some nulls. If that column is null, I want to condition output for it based on values in another column.

So if case when null (if c=80 then 'planb'; else if c=90 then 'planc')

How would you code that in an inline T-SQL statement?

开发者_运维问答

thanks.


COALESCE(YourColumn, CASE c WHEN 80 then 'planb' WHEN 90 THEN 'planc' END)


You can also use the nested case statement. Assuming that the first column is called DataColumn.

CASE 
  WHEN DataColumn IS NULL THEN 
    CASE c 
      WHEN 80 THEN 'planb' 
      WHEN 90 THEN 'planc' 
      ELSE 'no plan' 
    END 
  ELSE DataColumn 
END
0

精彩评论

暂无评论...
验证码 换一张
取 消