sql 服务器中 CONCAT 的意外行为,具有一些奇怪的非空值:它之后的值未添加到结果中

Unexpected behavior from CONCAT in sql server with some strange, non null value : the value after it are not added to the result

SELECT CONCAT('a', ISNULL(NameStudent, 'ccc'), 'b') as ShouldEndWithb,  NameStudent, LEN(NameStudent) as Length
FROM #Student

有一个奇怪的 NameStudent 值给出了 ssms 中此请求的以下结果。我不明白为什么 Concat 不以 b 结尾,为什么这个看似空的值的长度为 2。在理解这一点之后,我想知道我应该怎么做才能让 CONCAT 表现得像预期的那样。

ShouldEndWithb NameStudent Length
a 2

这是糟糕的数据,正是我所期望的:

0x00 是零字节字符并有效地终止字符串。

你需要修复源不发送0x00,因为数据已经没有了。