OPENXML
From: Mark (Mark_at_nowhere.com)
Date: 11/09/04
- Next message: Hugo Kornelis: "Re: update trigger help!!"
- Previous message: Hugo Kornelis: "Re: Need help with query"
- Next in thread: Cowboy (Gregory A. Beamer) - MVP: "RE: OPENXML"
- Reply: Cowboy (Gregory A. Beamer) - MVP: "RE: OPENXML"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 9 Nov 2004 16:21:12 -0600
Is there a way to use read data from an XML file, and insert it into a
table? The code example below is from BOL using OPENXML, but doesn't call
to a file directly.
Thanks in advance.
Mark
DECLARE @hDoc int
EXEC sp_xml_preparedocument @hDoc OUTPUT,
N'<ROOT>
<Customers CustomerID="XYZAA" ContactName="Joe"
CompanyName="Company1">
<Orders CustomerID="XYZAA"
OrderDate="2000-08-25T00:00:00"/>
<Orders CustomerID="XYZAA"
OrderDate="2000-10-03T00:00:00"/>
</Customers>
<Customers CustomerID="XYZBB" ContactName="Steve"
CompanyName="Company2">No Orders yet!
</Customers>
</ROOT>'
-- Use OPENXML to provide rowset consisting of customer data.
INSERT Customers
SELECT *
FROM OPENXML(@hDoc, N'/ROOT/Customers')
WITH Customers
-- Use OPENXML to provide rowset consisting of order data.
INSERT Orders
SELECT *
FROM OPENXML(@hDoc, N'//Orders')
WITH Orders
-- Using OPENXML in a SELECT statement.
SELECT * FROM OPENXML(@hDoc, N'/ROOT/Customers/Orders') with (CustomerID
nchar(5) '../@CustomerID', OrderDate datetime)
-- Remove the internal representation of the XML document.
EXEC sp_xml_removedocument @hDoc
- Next message: Hugo Kornelis: "Re: update trigger help!!"
- Previous message: Hugo Kornelis: "Re: Need help with query"
- Next in thread: Cowboy (Gregory A. Beamer) - MVP: "RE: OPENXML"
- Reply: Cowboy (Gregory A. Beamer) - MVP: "RE: OPENXML"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|