What is the Null Character literal in TSQL?

前端 未结 6 1857
暖寄归人
暖寄归人 2020-11-27 18:49

I am wondering what the literal for a Null character (e.g. \'\\0\') is in TSQL.

Note: not a NULL field value, but the null character (see link).

6条回答
  •  死守一世寂寞
    2020-11-27 19:30

    I just ran the test below on my server (2008) and it was successful. It may have to do with an ANSI setting. I'll try flipping some settings here and see if I can reproduce your issue.

    DECLARE @test_null_char VARCHAR(20)
    
    SET @test_null_char = 'aaa' + CHAR(0) + 'bbb'
    
    SELECT @test_null_char    -- Returns "aaa bbb"
    
    SET @test_null_char = REPLACE(@test_null_char, CHAR(0), 'ccc')
    
    SELECT @test_null_char    -- Returns "aaacccbbb"
    

提交回复
热议问题