我需要在存储过程中获取xml变量。
我试着这样:
DECLARE @xmlDoc XML;
SET @xmlDoc = (
WITH TEMP_TABLE (NAME, AGE)
AS
(
SELECT NAME, AGE FROM SOME_TABLE WHERE id=1
)
SELECT A.NAME, A.AGE, B.JOB
FROM TEMP_TABLE AS A, ANOTHER_TABLE AS B
WHERE A.id = 1 AND B.id = 1
FOR XML AUTO
);
但我收到了错误。
如何从With~starting子句中获取xml?有可能吗?
答案 0 :(得分:1)
我找到了解决方案!
DECLARE @xmlDoc XML;
;WITH TEMP_TABLE (NAME, AGE)
AS
(
-- select code here
)
SELECT @xmlDoc = (SELECT ... FROM ... WHERE ... FOR XML AUTO);