Export Xml Data Into Xml File

Bulk exporting XML data

USE tempdb
GO
IF OBJECT_ID('tempdb..myxmltable') IS NOT NULL 
    DROP TABLE myxmltable 
GO
DECLARE @Doc INT
DECLARE @XMlDoc NVARCHAR(1000)
SET @XMLDoc = N'<ROOT>
    <Customer CustomerID="JHO1" Name="Jack">
      <Order OrderID="1001" CustomerID="JH01"
             OrderDate="2009-07-04T00:00:00">
      <OrderDetail ProductID="11" Quantity="12"/>
      <OrderDetail ProductID="22" Quantity="10"/>
     </Order>
    </Customer>
<Customer CustomerID="SG01" Name="Steve">
     <Order OrderID="1002" CustomerID="SG01"
            OrderDate="2009-08-16T00:00:00">
    <OrderDetail ProductID="32" Quantity="3"/>
   </Order>
  </Customer>
</ROOT>'
SELECT  @XMlDoc AS xmldata
INTO    myxmltable
GO
xp_cmdshell 'bcp tempdb.dbo.myxmltable out "c:\temp\myxml.xml" -c -T -S"Server\SQLInstance"'
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License