I have an XML in this format
<tests>
<test>
<testid>1</testid>
<testval>8</testval>
<testname>
<testid>1</testid>
<testname>test 1</testname>
</testname>
</test>
<test>
<testid>2</testid>
<testval>5</testval>
<testname>
<testid>2</testid>
<testname>test 2</testname>
</testname>
</test>
</tests>
using TSQL/XML query how do I achieve this result
[Testid][TestVal][TestName]
1 8 Test 1
2 5 Test 2
Try this:
This gives you the desired output.
If you have a table of those XML columns, you might need to use a slightly different approach (using
CROSS APPLY):