Can't set output of 'WITH XMLNAMESPACES…FOR XML PATH' to a variable?

半世苍凉 提交于 2019-12-06 22:39:59

问题


I have a query like the following:

;WITH XMLNAMESPACES ( DEFAULT 'http://www.somewhere.com')
SELECT ( 'SOMETHING' )
FOR XML PATH('RootNode'), TYPE

Running this works fine. However, I run into troubles when I try to set the XML output to a variable like this:

DECLARE @MYXML AS XML

SELECT @MYXML = (
;WITH XMLNAMESPACES ( DEFAULT 'http://www.somewhere.com')
SELECT ( 'SOMETHING' )
FOR XML PATH('RootNode'), TYPE
)

This just give me a syntax error :-( Any ideas on how to accomplish this would be greatly appreciated.


回答1:


DECLARE @MYXML AS XML

;WITH XMLNAMESPACES ( DEFAULT 'http://www.somewhere.com')
SELECT @MYXML = (
   SELECT ( 'SOMETHING' )
   FOR XML PATH('RootNode'), TYPE)


来源:https://stackoverflow.com/questions/3230424/cant-set-output-of-with-xmlnamespaces-for-xml-path-to-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!