I was trying to get an XML from a SQL table:
My Table
------------
-- Table1 --
------------
ID Flight1 Flight2
--------------------------
1 F0123 F0789
2 F0345 F0678
Query:
Select
A.[ID],
A.[Flight1] as "FlightDescription/Number",
A.[Flight2] as "FlightDescription/Number"
from
[Table1] A
for xml path('Flight'), root('Flights')
My expected result is:
<Flights>
<Flight>
<ID>1</ID>
<FlightDescription>
<Number>F0123</Number>
</FlightDescription>
<FlightDescription>
<Number>F0789</Number>
</FlightDescription>
</Flight>
<Flight>
<ID>2</ID>
<FlightDescription>
<Number>F0345</Number>
</FlightDescription>
<FlightDescription>
<Number>F0678</Number>
</FlightDescription>
</Flight>
</Flights>
But instead of that I'm getting this:
<Flights>
<Flight>
<ID>1</ID>
<FlightDescription>
<Number>F0123F0789</Number>
</FlightDescription>
</Flight>
<Flight>
<ID>2</ID>
<FlightDescription>
<Number>F0345F0678</Number>
</FlightDescription>
</Flight>
</Flights>
I can figure it out... In my table i have more than 4 flight numbers for each ID so i would like to know if there is a way to have all of them in the way i need.
Thanks in advance!