We can convert the data table into the XML format using
- XML Raw
- XML Path
- XML Auto
Here I am going to use the XML Raw to convert the data table to XML format
XML Raw
RAW mode transform each row in the query result into an XML element. Below is the customer table structure.
select top 10 * from customers for xml raw('customer'),root('CustomerDetails')
The output of XML like below. Here we select top 10 record from customer table.
select top 2 * from customers for xml path('customer'),root('CustomerDetails')
XML Auto
select top 2 * from customers for xml auto,root('CustomerDetails')
Summary
So far we discussed How to convert table data into xml in sql server. Let us know if you have any question.
Post a Comment