Friday, February 24, 2012

Copy XML File to SQL Server Table.

A need, to take a XML File and copy the contents into SQL Server 2000 Table,
from a Store Procedure.
Necesito, tomar un archivo XML y copiar el contenido de este a una Tabla de
SQL SERVER 2000, desde un Procedimiento Almacenado.
Javier,
Take a look at OPENXML in the BOL. I have provided you with a code sample
below. Just remember to use sp_xml_preparedocument and sp_xml_removedocument
correctly or you will encounter a memory leak.
Good Luck.
DECLARE @.idoc INT
EXEC sp_xml_preparedocument @.idoc OUTPUT, '<Person ID="5"
FirstName="John" LastName="Doe">
<Sales QtyPurchased="2"/>
<Sales QtyPurchased="3"/>
</Person>'
select * from openxml(@.idoc, '*')
EXEC sp_xml_removedocument @.idoc
|||Thank you, very much Brian, but it not is the I like me. I need that in place
of I write '<Person ID="5"
> FirstName="John" LastName="Doe">
> <Sales QtyPurchased="2"/>
> <Sales QtyPurchased="3"/>
> </Person>', I will can writing the File.xml name.
Muchas Gracias Brian, pero no es lo que buscaba. Yo necesito que en lugar de
escribir <Person ID="5"
FirstName="John" LastName="Doe">
<Sales QtyPurchased="2"/>
<Sales QtyPurchased="3"/>
</Person>, yo pudiera escribir el nombre del archivo.xml.
Javier.
|||Sorry Javier, but you will have to open the file with an application and then
pass it to your stored procedure. If it must be contained within SQL Server
you could create a DTS to parse the xml file and then import it into your
table.
I hope that this helps!

No comments:

Post a Comment