SQL Server supports an enhancement to the T-SQL syntax that enables normal relational queries to output their result set as XML, using any of these four approaches:
FOR XML RAW
FOR XML AUTO
FOR XML EXPLICIT
FOR XML PATH
The first three of these options were introduced with the very first XML support in SQL Server 2000. We’ll start with these options and then cover later XML enhancements added in SQL Server 2008, which includes the fourth option (FOR XML PATH).
FOR XML RAW produces attribute-based XML. FOR XML RAW essentially creates a flat representation of the data in which each row returned becomes an element and the returned columns become the attributes of each element. FOR XML RAW also doesn’t interpret joins in any ...