CONCAT'ing NULL fields

前端 未结 11 850
小鲜肉
小鲜肉 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:55

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

    is recommended, but if you are really hooked on CONCAT, wrap it in {fn } and you can use the ODBC function like:

    SELECT {fn CONCAT(ISNULL(FirstName,''), ISNULL(LastName,''), ISNULL(Email,''))} as Vitals FROM MEMBERS
    

    If you need firstlast but just last when first is null you can do this:

    ISNULL(FirstName+' ','') + ISNULL(LastName,'')
    

    I added the space on firstname which might be null -- that would mean the space would only survive if FirstName had a value.

    To put them all together with a space between each:

    RTRIM(ISNULL(Firstname+' ','') + ISNULL(LastName+' ','') + ISNULL(Email,''))
    

提交回复
热议问题