SQL Server String Concatenation with Null

后端 未结 10 810
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 13:51

I am creating a computed column across fields of which some are potentially null.

The problem is that if any of those fields is null, the entire computed column will

10条回答
  •  悲哀的现实
    2020-11-27 14:39

    I just wanted to contribute this should someone be looking for help with adding separators between the strings, depending on whether a field is NULL or not.

    So in the example of creating a one line address from separate fields

    Address1, Address2, Address3, City, PostCode

    in my case, I have the following Calculated Column which seems to be working as I want it:

    case 
        when [Address1] IS NOT NULL 
        then (((          [Address1]      + 
              isnull(', '+[Address2],'')) +
              isnull(', '+[Address3],'')) +
              isnull(', '+[City]    ,'')) +
              isnull(', '+[PostCode],'')  
    end
    

    Hope that helps someone!

提交回复
热议问题