SQL Server String Concatenation with Null

后端 未结 10 804
隐瞒了意图╮
隐瞒了意图╮ 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:37

    From SQL Server 2012 this is all much easier with the CONCAT function.

    It treats NULL as empty string

    DECLARE @Column1 VARCHAR(50) = 'Foo',
            @Column2 VARCHAR(50) = NULL,
            @Column3 VARCHAR(50) = 'Bar';
    
    
    SELECT CONCAT(@Column1,@Column2,@Column3); /*Returns FooBar*/
    

提交回复
热议问题