SQLTeam.com | Weblogs | Forums

Insert data from XML (Almost works)


#1

Hello!

I've got the following Query:

DECLARE @x xml

SELECT @x = S
FROM OPENROWSET (BULK 'C:\XML.xml', SINGLE_BLOB) AS XML(S)

DECLARE @hdoc int

EXEC sp_xml_preparedocument @hdoc OUTPUT, @x

SELECT *
FROM OPENXML (@hdoc, '/Element', 2)
WITH (Element1 varchar(100),
Element2 varchar(100),
Element3 varchar(100))

EXEC sp_xml_removedocument @hdoc

And this works perfectly fine!
It takes all needed data from XML and views it.
Now I want to take the selected data and insert in into a database.

How do I insert this?

Hopefully someone can help me out,
Thanks!!


#2
INSERT INTO yourtable
SELECT *
FROM OPENXML (@hdoc, '/Element', 2)
WITH (Element1 varchar(100),
Element2 varchar(100),
Element3 varchar(100))