每当我将字符串解析为SQL XML数据类型时,我注意到只要空格和XML回车混合在一起,回车就消失了。如果它们不是混合的,那么一切都很好。有人知道为什么会这样吗?
请参阅下面的SQL示例代码
DECLARE @var XML
PRINT 'This is a statement with two XML carriage-return characters'
SET @var = CONVERT (XML,'<root>Dear Sir,

I am passing CR</root>',1)
SELECT @var
PRINT 'output is identical to a statement with two whitespace carriage-return characters'
SET @var = CONVERT (XML,'<root>Dear Sir,
I am passing CR</root>',1)
SELECT @var
PRINT 'Why does this statement only display one space? There is an XML carriage-return AND a whitespace carriage-return character.'
--Make sure there is no space after 
 after you've copied and pasted the code
SET @var = CONVERT (XML,'<root>Dear Sir,
I am passing CR</root>',1)
SELECT @var发布于 2010-05-27 20:32:33
在Windows中,行尾是CR-LF。在Unix中,行尾是CR。
在第一个示例中,您使用CR-CR。我猜SQL Server将它们解释为Unix样式的行尾,给出了两个空格。
您的第二个示例是在Windows中键入的,给出了CR-LF-CR-LF。这被解释为Windows样式的行尾,提供了两个空格。
您的第三个示例是CR-CR-LF。这显然被解释为Windows风格的行尾,给出了一个空格和一个无与伦比的CR。
如果您将第三个示例更改为使用CR-LF或
,它将显示两个空格。
https://stackoverflow.com/questions/2919952
复制相似问题