Skip to content
Advertisement

XQUERY -SQL Retrieve list of child and parent ID

How I can query the xml in order to obtain the following result? I am completely new on using XQuery.

XML sample:

And the result:

idAsig B1_1 B1_2 B1_3 B1_4 B1_5
1 NULL NULL NULL NULL NULL
2 1 0 N 8 4848
2 52 0 N 8 625
3 1 0 N 8 589
3 39 0 N 8 15647

I try this query

Advertisement

Answer

You can use CROSS APPLY on e.XMLData.nodes('/*:dec/*:asi') AS X(A) and then OUTER APPLY on X.A.nodes('*:asiB1') because you want all asi elements to appear in the query result regardless it has child asiB1 or not:

dbfiddle.uk demo

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