Click to See Complete Forum and Search --> : create XML from SQL table with multiple elements


asiasi
10-18-2010, 04:20 AM
Hi, I'm trying to create an xml document out of a sql 2005 table

I use this code in a query:

select p.name as "NAME"
from nop_product p
for xml path('PRODUCT'),ROOT('STORE')

my problem is that i need 3 level tree - all <PRODUCT> elements to be under <PRODUCTS> like this:

<STORE>
<PRODUCTS>
<PRODUCT>
<NAME> ..... </NAME>
</PRODUCT>
<PRODUCT>
<NAME> ....... </NAME>
</PRODUCT>
</PRODUCTS>
</STORE>

how do i do that? how do I add another permanent element after the ROOT tag and before the <PRODUCT> tag?
thanks