FOR XML Commands

SQL Server 2000 introduced an enhancement to the T-SQL syntax that enables normal relational queries to output their result set as XML, using any of these three approaches:

These three features are also supported in SQL Server 2005 and 2008. We’ll first discuss the features common to all three versions and then look closely at the new and enhanced features available in SQL Server 2008.

FOR XML RAW

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 special way. (Joins become relevant ...

Get Programming Microsoft® SQL Server™ 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.