How to return SQL Server 2005/2008 columns as identical child nodes using FOR XML query? -
By default I need to return some data from the SQL Server table in the following XML format:
& Lt; Querydata & gt; & Lt; Unit name = "person. Contact" & gt; & Lt; Line & gt; & Lt; Area name = "first name" & gt; Gustavo & lt; / Field & gt; & Lt; Area name = "Last name" & gt; Akchong & lt; / Field & gt; & Lt; / Row & gt; & Lt; Line & gt; & Lt; Area name = "first name" & gt; Catherine & lt; / Field & gt; & Lt; Area name = "Last name" & gt; Abel & lt; / Field & gt; & Lt; / Row & gt; ... & lt; / Unit & gt; & Lt; / Querydata & gt;
I came with the following SQL statement:
Select "Personname.Contact" for "@name" (FirstName, choose LastName from PersonName) For the XML path ('unit') for the XML path ('line', TYPE), contact the root ('querydata')
which produces this output: / P>
& lt; Querydata & gt; & Lt; Unit name = "person. Contact" & gt; & Lt; Line & gt; & Lt; FirstName & gt; Gustavo & lt; / First name & gt; & Lt; Last name & gt; Achong & lt; / Last name & gt; & Lt; / Row & gt; & Lt; Line & gt; & Lt; FirstName & gt; Catherine & lt; / First name & gt; & Lt; Last name & gt; Abel & lt; / Last name & gt; & Lt; / Row & gt; .... & lt; / Unit & gt; & Lt; / Querydata & gt;
But I have not found any further. Thanks!
You need to negate your data.
Along with the rows of a subquery:
or something with these lines ...
I have a SQL with me ( Today is not on my iPhone), but I'm thinking about:
Select "person.Contact" as "@name", (select 'first name' In the form [@name], first name [*] as the union, all 'last names' Contact [XML path format ( 'Unit'), root (XML Path 'Cvereedeta') ( 'line'), TYPE).
Comments
Post a Comment