I am trying to update a SQL Server database using an XML file that I will be given. I am trying to use XQuery to insert part of each XML record, but am having difficulty getting the values of more than one node to the corresponding columns of the database. Here is the code that I am using:
USE GOCO
GO
DECLARE @x XML
SET @x = '<Table6>
<Flt_x0020_No>1</Flt_x0020_No>
<AvNo>2046</AvNo>
<Date>2010-05-19T00:00:00+04:30</Date>
<Takeoff_x0020_Time>14:15</Takeoff_x0020_Time>
<Land_x0020_Time>15:09</Land_x0020_Time>
<Total_x0020_Flt_x0020_Time>0.9</Total_x0020_Flt_x0020_Time>
</Table6>
<Table6>
<Flt_x0020_No>3460</Flt_x0020_No>
<AvNo>2489</AvNo>
<Date>2013-01-15T00:00:00+04:30</Date>
<Takeoff_x0020_Time>8:40</Takeoff_x0020_Time>
<Land_x0020_Time>13:05</Land_x0020_Time>
<Total_x0020_Flt_x0020_Time>4.5</Total_x0020_Flt_x0020_Time>
</Table6>'
insert into Flight(
FltNo,
AvNo
)
select
Table1.Column1.value('text() [1]', 'varchar(50)'),
Table1.Column1.value('text() [2]', 'varchar(50)')
from @x.nodes('/Table6/Flt_x0020_No, /Table6/AvNo') As Table1(Column1)
Which gives me:
FltNo|AvNo
1 |Null
3460 |Null
2046 |Null
2489 |Null
I am looking for a result of:
FltNo|AvNo
1 |2046
3460 |2489
Does anybody know how to do this? Thanks.