AUTO Mode

FOR XML AUTO gives you more control than RAW mode over the XML fragment that's produced. To begin with, each row in the result set is named after the table, view, or table-valued UDF that produced it. For example, here's a basic FOR XML AUTO query:

SELECT CustomerId, CompanyName
FROM Customers FOR XML AUTO

(Results abridged)

 XML_F52E2B61-18A1-11d1-B105-00805F49916B --------------------------------------------------------------------------- <Customers CustomerId="ALFKI" CompanyName="Alfreds Futterkiste"/><>Customers CustomerId="ANATR" CompanyName="Ana Trujillo Emparedados y helados"/><>Customers CustomerId="ANTON" CompanyName="Antonio Moreno Taquer?a"/><Customers CustomerId="AROUT" CompanyName="Around the Horn"/><>Customers CustomerId="VINET" ...

Get Guru's Guide to SQL Server™ Stored Procedures, XML, and HTML, The 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.