CONCAT'ing NULL fields

前端 未结 11 841
小鲜肉
小鲜肉 2021-02-01 00:25

I have a table with three fields, FirstName, LastName and Email.

Here\'s some dummy data:

FirstName | LastName | Email
Adam        West       adam@west.c         


        
11条回答
  •  情歌与酒
    2021-02-01 00:59

    SQL Server does not have a CONCAT function.
    (Update: Starting from MS SQL Server 2012 it was introduced CONCAT function)

    In the default SQL Server behavior, NULLs propagate through an expression.

    In SQL Server, one would write:

    SELECT FirstName + LastName + Email as Vitals FROM MEMBERS
    

    If you need to handle NULLs:

    SELECT ISNULL(FirstName, '') + ISNULL(LastName, '') + ISNULL(Email, '') as Vitals FROM MEMBERS
    

提交回复
热议问题