我在存储过程中有一个查询,它检索一些 XML 格式的数据以在变量中返回@xml_data
,如下所示:
SELECT @xml_data = (
SELECT * FROM (
SELECT 1 AS Tag
,0 AS Parent
.....
FROM MyTable
WHERE id = @id
UNION ALL
SELECT 2 AS Tag
,1 AS Parent
....
FROM MyTable2
WHERE id = @id
UNION ALL
SELECT 3 AS Tag
,2 AS Parent
....
FROM MyTable3
WHERE id = @id
) results
FOR XML EXPLICIT, TYPE)
这就像众所周知的梦想一样工作:)
但是,我想将一个标头连接到这个 XML(例如<xml version="1.0" encoding="ISO-8859-1"/>
),但不知道该怎么做。我尝试转换为NVARCHAR
,在一个语句中选择两个变量,但似乎无法正确处理。
有人可以帮忙吗??
谢谢 :)