我有一个表格,其结构如下:
------------------------------ LocationID | AccountNumber ------------------------------ long-guid-here | 12345 long-guid-here | 54321
要传递到另一个存储过程,我需要XML看起来像这样:
<root> <clientID>12345</clientID> <clientID>54321</clientID> </root>
到目前为止我能做到的最好的就是这样:
<root clientID="10705"/>
我正在使用这个sql语句:
SELECT 1 as tag,null as parent,AccountNumber as 'root!1!clientID' FROM Location.LocationMDAccount WHERE locationid = 'long-guid-here' FOR XML EXPLICIT
到目前为止,我已经查看了the MSDN page的文档,但是我没有得到预期的结果.
@公斤,
你的实际给了我这个输出:
<root> <Location.LocationMDAccount> <clientId>10705</clientId> </Location.LocationMDAccount> </root>
我现在要坚持使用Chris Leon的FOR XML EXPLICIT.
解决方法
尝试
SELECT 1 AS Tag,0 AS Parent,AccountNumber AS [Root!1!AccountNumber!element] FROM Location.LocationMDAccount WHERE LocationID = 'long-guid-here' FOR XML EXPLICIT