Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Create and retun xml in sql2008

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2009-10-05 : 11:19:33
i want to create xml from a table, with a sturcture like :
<root>
<a>
<x>dd</x>
<y>dd</y>
</a>
<a>
<x>23434</x>
<y>dfgfgd</y>
</a>
</root>

how do i do it?
Thanks
Peleg

acd
Starting Member

6 Posts

Posted - 2009-10-06 : 11:44:53
Hi,


select x,y
from
(
select x='dd', y='dd'
union all
select x='23434', y='dfgfgd'
) a
for xml auto, elements, root('root')


Regards,
Bartek
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2009-10-06 : 15:39:03
Thanks.
is there a way i cant put the result into a variable like
Decalre @myXml nvarchar(1000)?
Go to Top of Page
   

- Advertisement -