Groups | Blog | Home
all groups > sql server (alternate) > november 2004 >

sql server (alternate) : Import XML file to database (MS Server 2000) using procedure (transact sql) ???


Szaki
11/10/2004 12:58:19 PM
I must import some exemplary file to database (MS Srrver 2000) ofcourse
using procedure Transact SQL.
This file must:
1.Read the xml file
2. Create table
3. Import this date from xml file to my database

Ps. I create procedure who File xml imports to base, but unfortunately she
only schedule when earlier create a table or table is created.So I need (I
think) create such mini parser in language transact SQL.
Does someone have some ideas?

For every help Thanks

==== example file xml ===========================================
<root>
<Cust>
<IDosoby>1</IDosoby>
<Imie>Lukasz</Imie>
<Nazwisko>Przypadek</Nazwisko>
</Cust>
<Cust>
<IDosoby>2</IDosoby>
<Imie>Dariusz </Imie>
<Nazwisko>Mroz</Nazwisko>
</Cust>
<Cust>
<IDosoby>3</IDosoby>
<Imie>Tomasz</Imie>
<Nazwisko>Kolo</Nazwisko>
</Cust>
</root>
===========================================================
--
Luk


Szaki
11/10/2004 1:45:46 PM
Thanks,
Could you correct my procedure that she acted correctly, becouse I'm a
beginning programist.
thanks for any help


U¿ytkownik "Vinod Kumar" <vinodk_sct@NO_SPAM_hotmail.com> napisa³ w
wiadomo¶ci news:cmt0tj$1fe$1@news01.intel.com...
[quoted text, click to view]

Uri Dimant
11/10/2004 2:41:24 PM
Hi
May be it is not exactly what you wanted but I ma sure you will get an idea.

declare @list varchar(8000)
declare @hdoc int
set @list='<Northwind..Orders OrderId="10643"
CustomerId="ALFKI"/><Northwind..Orders OrderId="10692" CustomerId="ALFKI"/>'
select @list='<Root>'+ char(10)+@list
select @List = @List + char(10)+'</Root>'
exec sp_xml_preparedocument @hdoc output, @List

select OrderId,CustomerId
from openxml (@hdoc, '/Root/Northwind..Orders', 1)
with (OrderId int,
CustomerId varchar(10)
)
exec sp_xml_removedocument @hdoc





[quoted text, click to view]

Vinod Kumar
11/10/2004 5:47:54 PM
Not sure of the exact requirement. But if you can parse the XML and then
using OPENXML shred it into a new table.

SELECT * INTO <MyNewTable>
FROM OPENXML (@idoc, '/root/')

Where @idoc is the document handle of the internal representation of an XML
document.

--
HTH,
Vinod Kumar
MCSE, DBA, MCAD, MCSD
http://www.extremeexperts.com

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp

[quoted text, click to view]

AddThis Social Bookmark Button