I have an XML similar to this structure.
<Root>
<id>a2bh5</id>
<Student ID="123">
<Name>abc<Name>
<course>ETL<course>
<Scores>
<Score>
<Subject>SSIS<subject>
<grade>B<grade>
</score>
<Score>
<Subject>Informatica<subject>
<grade>C<grade>
</score>
</Scores>
</Student>
<Student ID="456">
<Name>xyz<Name>
<course>ETL<course>
<Scores>
<Score>
<Subject>Pentaho<subject>
<grade>F<grade>
</score>
<Score>
<Subject>Datastage<subject>
<grade>A<grade>
</score>
</Scores>
</Student>
</Root>
I would like to get details from child nodes(scores) along with its parent attribute(Id) using Xquery in SQL server.
The query result is expected like below for all subjects. Please help.
Student_Id subject grade
========================
123 SSIS B
Once your sample XML is cleaned up and all tags are properly closed, try this:
This gives an output of: