回複:請教SQL問題,謝謝

回答: 請教SQL問題,謝謝greentree20102010-11-19 08:51:41

DECLARE @idoc int
DECLARE @doc varchar(1000)
SET @doc ='
<ROOT>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
   <Order OrderID="10248" CustomerID="VINET" EmployeeID="5"
           OrderDate="1996-07-04T00:00:00">
      <OrderDetail ProductID="11" Quantity="12"/>
      <OrderDetail ProductID="42" Quantity="10"/>
   </Order>
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
   <Order OrderID="10283" CustomerID="LILAS" EmployeeID="3"
           OrderDate="1996-08-16T00:00:00">
      <OrderDetail ProductID="72" Quantity="3"/>
   </Order>
</Customer>
</ROOT>'
--Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
-- SELECT stmt using OPENXML rowset provider
SELECT *
FROM   OPENXML (@idoc, '/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 @idoc

所有跟帖: 

回複:回複:請教SQL問題,謝謝 -greentree2010- 給 greentree2010 發送悄悄話 (172 bytes) () 11/19/2010 postreply 11:46:48

This sample looks lovely -胡說之- 給 胡說之 發送悄悄話 胡說之 的博客首頁 (251 bytes) () 11/19/2010 postreply 14:02:49

請您先登陸,再發跟帖!