Using FOR XML AUTO

For greater control over the names and structure of your XML, use AUTO mode. AUTO mode facilitates the naming of XML elements with something other than “row.” Element names correspond to the name or alias of the selected tables.

AUTO mode creates a structured view of data that mirrors the relationships of selected tables by nesting XML elements selected from multiple tables. A nested or child element is one that is enclosed by another element, known as its parent element. Listing 41.3 shows an example of element nesting.

Listing 41.3. FOR XML AUTO Enables Nesting of XML Elements Based on Relationships Expressed in a Join
 SELECT Customer.CustomerID CID, CompanyName CO, ContactName CN, OrderID FROM Customers Customer JOIN Orders ...

Get Microsoft® SQL Server™ 2000 Unleashed, Second Edition 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.