Examples: Using AUTO Mode
The following examples illustrate the use of AUTO mode.
The following examples illustrate the use of AUTO mode. Many of these queries are specified
against bicycle manufacturing instructions XML documents that are stored in the Instructions
column of the ProductModel table in the AdventureWorks2022 sample database.
This query retrieves customer, order, and order detail information for a specific customer.
Because the query identifies,
,
,
, and
table aliases,
corresponding elements are generated by the
mode. Again, the order in which tables are
identified by the columns specified in the
clause determine the hierarchy of these
elements.
This is the partial result.
XML
Cust
OrderHeader
Detail
Product
AUTO
SELECT
USE
AdventureWorks2022;
GO
SELECT
Cust.CustomerID,
OrderHeader.CustomerID,
OrderHeader.SalesOrderID,
Detail.SalesOrderID, Detail.LineTotal, Detail.ProductID,
Product.Name,
Detail.OrderQty
FROM
Sales.Customer
AS
Cust
INNER
JOIN
Sales.SalesOrderHeader
AS
OrderHeader
ON
Cust.CustomerID = OrderHeader.CustomerID
INNER
JOIN
Sales.SalesOrderDetail
AS
Detail
ON
OrderHeader.SalesOrderID = Detail.SalesOrderID
INNER
JOIN
Production.Product
AS
Product
ON
Product.ProductID = Detail.ProductID
WHERE
Cust.CustomerID
IN (29672, 29734)
ORDER
BY
OrderHeader.CustomerID,
OrderHeader.SalesOrderID
FOR
XML
AUTO
;