DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
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>&lt;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"&gt;&lt;net:AddressID&gt;635&lt;/net:AddressID&gt;&lt;net:AddressTypeID&gt;3&lt;
/net:AddressTypeID&gt;&lt;net:ModifiedDate&gt;2002-09-01T00:00:00&lt;/net:ModifiedDate&gt;&lt;/ca&gt;</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>&lt;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"&gt;&lt;net:AddressID&gt;636&lt;/net:AddressID&gt;&lt;net:AddressTypeID&gt;3&lt;
/net:AddressTypeID&gt;&lt;net:ModifiedDate&gt;2003-07-01T00:00:00&lt;/net:ModifiedDate&gt;&lt;/ca&gt;</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>&lt;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"&gt;&lt;net:AddressID&gt;637&lt;/net:AddressID&gt;&lt;net:AddressTypeID&gt;3&lt;
/net:AddressTypeID&gt;&lt;net:ModifiedDate&gt;2003-09-01T00:00:00&lt;/net:ModifiedDate&gt;&lt;/ca&gt;</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>&lt;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"&gt;&lt;net:AddressID&gt;638&lt;/net:AddressID&gt;&lt;net:AddressTypeID&gt;3&lt;
/net:AddressTypeID&gt;&lt;net:ModifiedDate&gt;2003-08-01T00:00:00&lt;/net:ModifiedDate&gt;&lt;/ca&gt;</net:Customer>
 
*/
 

 

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE