SQL Server 2005 For XML Explicit - Need help formatting SQL Server 2005 For XML Explicit - Need help formatting xml xml

SQL Server 2005 For XML Explicit - Need help formatting


try

SELECT    1 AS Tag,    0 AS Parent,    AccountNumber AS [Root!1!AccountNumber!element]FROM    Location.LocationMDAccountWHERE    LocationID = 'long-guid-here'FOR XML EXPLICIT


Try this, Chris:

SELECT    AccountNumber as [clientId]FROM    Location.Location rootWHERE    LocationId = 'long-guid-here'FOR    XML AUTO, ELEMENTS

TERRIBLY SORRY! I mixed up what you were asking for. I prefer the XML AUTO just for ease of maintainance, but I believe either one is effective. My apologies for the oversight ;-)


Using SQL Server 2005 (or presumably 2008) I find for XML PATH to allow for much easier to maintain SQL than for XML Explicit (particularly once the SQL is longer).

In this case:

SELECT AccountNumber as "clientID"FROM Location.LocationMDAccountWHERE locationid = 'long-guid-here'FOR XML PATH (''), Root ('root');