Technical Article

Using sp_xml_preparedocument

,

Script showing how to use these functions.

DECLARE @hdoc int
DECLARE @doc varchar(2000)
SET @doc = '
<ROOT>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
   <Order CustomerID="VINET" EmployeeID="5" OrderDate="1996-07-04T00:00:00">
      <OrderDetail OrderID="10248" ProductID="11" Quantity="12"/>
      <OrderDetail OrderID="10248" ProductID="42" Quantity="10"/>
   </Order>
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
   <Order CustomerID="LILAS" EmployeeID="3" OrderDate="1996-08-16T00:00:00">
      <OrderDetail OrderID="10283" ProductID="72" Quantity="3"/>
   </Order>
</Customer>
</ROOT>'


EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc

SELECT * FROM OPENXML( @hdoc, '/ROOT/Customer/Order/OrderDetail',2)
WITH (OrderID       int         '@OrderID',
CustomerID  varchar(10) '../@CustomerID',
        OrderDate   datetime    '../@OrderDate',
        ProdID      int         '@ProductID',
        Qty         int         '@Quantity')

EXEC sp_xml_removedocument @hdoc

Rate

1 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

1 (1)

You rated this post out of 5. Change rating