将表格结果转换为xml
时,垃圾字符会出现以下是我正在使用的SQL代码
CREATE TABLE #tbl
(
RowID INT
, Comments NVARCHAR(MAX)
)
-------------------------------
INSERT INTO #Tbl(RowID, Comments) VALUES (1, '&test 123123123 & test
test123&
' )
INSERT INTO #Tbl(RowID, Comments) VALUES (2, '&test 123123123 & test' )
INSERT INTO #Tbl(RowID, Comments) VALUES (3, '&test 123123123 & test
test123&
&&' )
------------------------------------
SELECT
(
SELECT distinct
RowId
,Comments AS Comments
FROM
#tbl AS t
FOR XML RAW, TYPE
)FOR XML PATH('Table'), TYPE
------------------------------------
DROP TABLE #tbl
任何人都可以在这方面帮助我。提前谢谢。
答案 0 :(得分:0)
正如其他人所说,它们不是垃圾字符,它们更像是转义字符。
为了您的目的,所说的宽度,替换
SELECT ( SELECT distinct RowId , REPLACE(Comments, '&', '&') AS Comments
FROM #tbl AS t
FOR XML RAW, TYPE )
FOR XML PATH('Table'), TYPE