XQUERY big problem
- From: "aja74" <aja74toaja74@xxxxxxxxx>
- Date: Fri, 29 Feb 2008 12:25:43 +0100
Hello
I try import data from XML file to MSSQL2005 using XQUERY
xml like:
<start>
<section>
<data1> </data1>
<data2> </data2>
<data3> </data3>
<person> P1 </person>
<person> P2 </person>
<car>
<car_name>CC1 </car_name>
</car>
</section>
<section>
<data1> </data1>
<data2> </data2>
<data3> </data3>
<person> P1 </person>
<car>
<car_name>C1 </car_name>
</car>
<car>
<car_name>C2 </car_name>
</car>
<car>
<car_name>C3 </car_name>
</car>
</section>
....
</start>
As you see data1,data2,data3 is in each <section> (i do not know how many
in each xml will be <sections>) but tag <person> or <car> can be one or
more I do not know how many the same <car> can be on or more or can not be
anything.
So I think i must prepare 3 tables, one for data1-3 one for persons and
one for cars
but how can i know that this car is from exactly this <section> and
person isfrom this section?
I can import this file into:
DECLARE @xVar XML
insert into tab_data
SELECT
tab.col.value('data1[1]', 'nvarchar(30)') As data1,
tab.col.value('data2[1]', 'nvarchar(30)') As data2,
tab.col.value('data3[1]', 'nvarchar(30)') As data3
from @xVar.nodes('//START//SECTION') tab(col)
insert into tab_cars
SELECT
tab.col.value('car_name[1]', 'nvarchar(30)') As car_name
from @xVar.nodes('//START//SECTION//car') tab(col)
insert into tab_persons
SELECT
tab.col.value('person[1]', 'nvarchar(30)') As person
from @xVar.nodes('//START//SECTION') tab(col)
and now how connect tables tab_cars, tab_persons and tab_data
How to know that car CC1 own person PP1 and PP2 and so one.
How to import this data using XQuery? And make connection between tables.
Best Regards
AJA
.
- Follow-Ups:
- Re: XQUERY big problem
- From: Mike C#
- Re: XQUERY big problem
- Prev by Date: Re: how to insert xml into sql 2005
- Next by Date: Re: Query an xml column
- Previous by thread: Re: how to insert xml into sql 2005
- Next by thread: Re: XQUERY big problem
- Index(es):
Relevant Pages
|