Basically I need to return some data from a SQL Server table in the following XML format:
<querydata>
<entity name="Person.Contact">
<row>
<field name="FirstName">Gustavo</field>
<field name="LastName">Achong</field>
</row>
<row>
<field name="FirstName">Catherine</field>
<field name="LastName">Abel</field>
</row>
...
</entity>
</querydata>
I have come up with the following SQL statement:
select 'Person.Contact' as "@name",
(select FirstName, LastName from Person.Contact for XML path('row'), TYPE)
for XML path('entity'), root('querydata')
Which produces this output:
<querydata>
<entity name="Person.Contact">
<row>
<FirstName>Gustavo</FirstName>
<LastName>Achong</LastName>
</row>
<row>
<FirstName>Catherine</FirstName>
<LastName>Abel</LastName>
</row>
....
</entity>
</querydata>
But I have gotten no further. Thanks!