Is there a built-in stored procedure in SQL Server 2000 that returns the sql table structure of XML format

10 pts.
Tags:
SQL Server 2000
SQL Server import/export
XML
i have a xml file.i want to insert the contents of the xml file into a table in sql server 2005.

Answer Wiki

Thanks. We'll let you know when a new response is added.

You will want to use the OPENXML command to get the data from the XML document.

First use the BULK INSERT command to load the entire XML document into a temporary table. You are going to put the entire XML Document into a single field of a single record.

<pre>CREATE TABLE #XMLData
(XMLData XML)

BULK INSERT #XMLData FROM ‘D:\YourXMLFile.xml’ WITH BULK</pre>

Once you have done this you can load the XML data from the table into an XML variable. From there you can use the sp_xml_preparedocument, then the OPENXML command to view the data.

<pre>DECLARE @hDoc INT
DECLARE @XML XML

SELECT @XML = XMLData
FROM #XMLData

EXEC sp_xml_preparedocument @hDoc OUTPUT, @XML

INSERT INTO YourTable
SELECT *
FROM OPENXML (@hDoc, ‘/root/YourPath’)
WITH (YourId INT ‘@IdField’,
LastName VARCHAR(40) ‘@LastName’)

EXEC sp_xml_removedocument @hDoc

GO</pre>

Make sure you remove the document from the XML DOM using the sp_xml_removedocument procedure. Otherwise SQL Server will keep the XML Document in memory.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following