T-SQL CASE Clause: How to specify WHEN NULL

后端 未结 15 1968
心在旅途
心在旅途 2020-11-28 05:42

I wrote a T-SQL Statement similar like this (the original one looks different but I want to give an easy example here):

SELECT first_name + 
    CASE last_na         


        
15条回答
  •  再見小時候
    2020-11-28 06:00

    The problem is that null is not considered equal to itself, hence the clause never matches.

    You need to check for null explicitly:

    SELECT CASE WHEN last_name is NULL THEN first_name ELSE first_name + ' ' + last_name
    

提交回复
热议问题