SQL #39;stuff#39; and #39;FOR XML PATH#39; generating strange symbols(SQL“东西和“FOR XML PATH生成奇怪的符号)
问题描述
我在 SQL Server 中较大的 Select 语句中有以下查询:
CONVERT(NVARCHAR(2000),stuff((SELECT '; ' + IsNull(D2.SelectedComments,'')来自#StudentDetails D2WHERE D2.STUD_PK = A.STUD_PK AND D2.CourseNo = A.CourseNoAND D2.Section = A.SectionFOR XML PATH('')),1,2,'')) AS SelectedComments,
此列在某些条目后生成一些奇怪的符号,例如这种方法令人满意.
.我不明白 .
来自哪里.在此之前,我尝试执行 SELECT SelectedComments FROM #StudentDetails
,但我没有看到 .
.谁能告诉它可能来自哪里?
如果你修改你对 For Xml Path 的使用,它会为你做转义,你不需要求助于使用 Replace 函数:
>
, 东西((选择 ';' + IsNull( D2.SelectedComments, '' )来自#StudentDetails 作为 D2其中 D2.Stud_PK = A.Stud_PK和 D2.CourseNo = A.CourseNoD2.Section = A.Section对于 Xml Path(''),输入).value('.', 'nvarchar(max)'), 1, 2, '') 作为 SelectedComments
I have the following query inside a larger Select statement in SQL Server:
CONVERT(NVARCHAR(2000),stuff((SELECT '; ' + IsNull(D2.SelectedComments,'')
FROM #StudentDetails D2
WHERE D2.STUD_PK = A.STUD_PK AND D2.CourseNo = A.CourseNo
AND D2.Section = A.Section
FOR XML PATH('')),1,2,'')) AS SelectedComments,
This column is generating some strange symbols after certain entries such as This approach is satisfactory .
. I don't understand where the .
is coming from. I tried doing SELECT SelectedComments FROM #StudentDetails
right before this and I don't see the .
. Can anyone tell where it could be coming from?
If you modify your use of For Xml Path, it will do the unescaping for you and you won't need to resort to using the Replace function:
, Stuff(
(
Select '; ' + IsNull( D2.SelectedComments, '' )
From #StudentDetails As D2
Where D2.Stud_PK = A.Stud_PK
And D2.CourseNo = A.CourseNo
And D2.Section = A.Section
For Xml Path(''), type
).value('.', 'nvarchar(max)')
, 1, 2, '') As SelectedComments
这篇关于SQL“东西"和“FOR XML PATH"生成奇怪的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL“东西"和“FOR XML PATH"生成奇怪的符号


基础教程推荐
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01