Monday, July 9, 2007

SQL: Returning XML in a query

Sometimes you want your query result to return as XML. MS SQL server 2005 offers this feature, and it's quite simple:


Normal result

Select a, b from myTable



XML result but returning coloumn values as XML-attributes

Select a, b from myTable for XML AUTO



XML result column as individual elements

Select a, b from myTable for XML AUTO, ELEMENTS

No comments: