Skip to content
Advertisement

Generate XML path format from SQL table

I was trying to get an XML from a SQL table:

My Table

My expected result is:

But instead of that I’m getting this:

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!

Advertisement

Answer

Here is another slightly more elaborate way. XQuery and its FLWOR expression. This way you shape your XML explicitly. It is easy to create, understand, make any modifications, and maintain down the road.

SQL

Output

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement