SQL Server String Concatenation with Null

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

    This example will help you to handle various types while creating insert statements

    select 
    'insert into doc(Id, CDate, Str, Code, Price, Tag )' + 
    'values(' +
          '''' + convert(nvarchar(50), Id) + ''',' -- uniqueidentifier
        + '''' + LEFT(CONVERT(VARCHAR, CDate, 120), 10) + ''',' -- date
        + '''' + Str+ ''',' -- string
        + '''' + convert(nvarchar(50), Code)  + ''',' -- int
        + convert(nvarchar(50), Price) + ',' -- decimal
        + '''' + ISNULL(Tag, '''''') + '''' + ')'  -- nullable string
    
     from doc
     where CDate> '2019-01-01 00:00:00.000'
    

提交回复
热议问题