Archive for September 3rd, 2008
Getting sql query output in XML
Most of the time we will be executing sql queries and getting results as number of rows mainly records. In order to get those records in the XML format we can modify our existing query by adding just few keywords. In the result of those queries we will get the result in raw or formatted XML.
Normal query
Select * from customers
Query for getting result in XML format
Select * from customer FOR XML RAW or
Select * from custoemr FOR XML AUTO
Now we will get the result in well formed xml by getting the elements well tagged and root node as custoemr with following query
Select * from customer FOR XML AUTO, ELEMENTS, ROOT(‘customer’)



