SQL Server 2005 For XML Explicit-需要格式设置帮助吗
我有一张结构如下的桌子:SQL Server 2005 For XML Explicit-需要格式设置帮助吗,sql,xml,sql-server-2005,formatting,for-xml,Sql,Xml,Sql Server 2005,Formatting,For Xml,我有一张结构如下的桌子: 位置ID 帐号 这里的长guid 12345 这里的长guid 54321 试一试 试试这个,克里斯: SELECT AccountNumber as [clientId] FROM Location.Location root WHERE LocationId = 'long-guid-here' FOR XML AUTO, ELEMENTS 非常抱歉!我把你的要求搞混了。我更喜欢XML AUTO,只是为了易于维护,但我相信两者都是
位置ID 帐号 这里的长guid 12345 这里的长guid 54321 试一试 试试这个,克里斯:
SELECT
AccountNumber as [clientId]
FROM
Location.Location root
WHERE
LocationId = 'long-guid-here'
FOR
XML AUTO, ELEMENTS
非常抱歉!我把你的要求搞混了。我更喜欢XML AUTO,只是为了易于维护,但我相信两者都是有效的。我为疏忽道歉;-) 我是用:
select
1 as tag,
null as parent,
AccountNumber as 'root!1!clientID!element'
from
Location.LocationMDAccount
where
locationid = 'long-guid-here'
for xml explicit
使用SQLServer2005(或者大概是2008),我发现FORXMLPATH比FORXMLEXPLICIT更易于维护SQL(特别是在SQL更长的时候)
在这种情况下:
SELECT AccountNumber as "clientID"
FROM Location.LocationMDAccount
WHERE locationid = 'long-guid-here'
FOR XML PATH (''), Root ('root');
选择1作为标记,
作为父项为空,
帐户号为'clientID!1.元素'
来自Location.LocationMDAccount
其中locationid='long guid here'
对于XML显式,根('root')
SELECT AccountNumber as "clientID"
FROM Location.LocationMDAccount
WHERE locationid = 'long-guid-here'
FOR XML PATH (''), Root ('root');
SELECT 1 as tag,
null as parent,
AccountNumber as 'clientID!1!!element'
FROM Location.LocationMDAccount
WHERE locationid = 'long-guid-here'
FOR XML EXPLICIT, root('root')