| How to
use XML AUTO and XML PATH? |
|
Execute the following
SQL Server T-SQL scripts in Management Studio Query Editor to demonstrate how to select a subset of customers into an XML result set. USE AdventureWorks; WITH XMLNAMESPACES ( 'http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-16T14:02:00' as net, 'http://schemas.microsoft.com/office/infopath/2003' as xd) SELECT AccountNumber "net:AccountNumber", CustomerType "net:CustomerType", ( SELECT [AddressID] "net:AddressID" ,[AddressTypeID] "net:AddressTypeID" ,[ModifiedDate] "net:ModifiedDate" FROM [Sales].[CustomerAddress] ca WHERE ca.[CustomerID] =c.CustomerID for XML AUTO, elements ) FROM [Sales].[Customer] c WHERE TerritoryID = 10 FOR XML PATH ('net:Customer') GO /* Partial results <net:Customer xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:net="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-16T14:02:00"> <net:AccountNumber>AW00000016</net:AccountNumber> <net:CustomerType>S</net:CustomerType><ca xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:net="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-16T14:02:00"><net:AddressID>635</net:AddressID><net:AddressTypeID>3< /net:AddressTypeID><net:ModifiedDate>2002-09-01T00:00:00</net:ModifiedDate></ca></net:Customer> <net:Customer xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:net="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-16T14:02:00"> <net:AccountNumber>AW00000034</net:AccountNumber> <net:CustomerType>S</net:CustomerType><ca xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:net="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-16T14:02:00"><net:AddressID>636</net:AddressID><net:AddressTypeID>3< /net:AddressTypeID><net:ModifiedDate>2003-07-01T00:00:00</net:ModifiedDate></ca></net:Customer> <net:Customer xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:net="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-16T14:02:00"> <net:AccountNumber>AW00000052</net:AccountNumber> <net:CustomerType>S</net:CustomerType><ca xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:net="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-16T14:02:00"><net:AddressID>637</net:AddressID><net:AddressTypeID>3< /net:AddressTypeID><net:ModifiedDate>2003-09-01T00:00:00</net:ModifiedDate></ca></net:Customer> <net:Customer xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:net="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-16T14:02:00"> <net:AccountNumber>AW00000070</net:AccountNumber> <net:CustomerType>S</net:CustomerType><ca xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:net="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-16T14:02:00"><net:AddressID>638</net:AddressID><net:AddressTypeID>3< /net:AddressTypeID><net:ModifiedDate>2003-08-01T00:00:00</net:ModifiedDate></ca></net:Customer> */
|
| |
| SQLUSA.com
Home Page |
|
|
SQL Server Training at www.sqlusa.com.
Microsoft SQL Server 2012 Training Videos at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
|
|
|
FREE SS SQL / BI OLAP Short Videos on YOUTUBE.com |
|
Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts |
Copyright 2005-2012, SMI Corp. All Rights Reserved.
SQL Server 2012 is a program product of Microsoft Corporation. SQL Server 2008 is a program product of Microsoft Corporation. SQL Server 2005 is a program product of Microsoft Corporation. SQL Server 2000 is a program product of Microsoft Corporation. |
|