I try to return a set of result from an xml document using xquery but I didn't figure out.
Here are my queries:
DECLARE @Data xml
SET @Data='<main>
<person>
<name>Daniel</name>
<cars>
<model>y75</model>
<model>b25</model>
</cars>
</person>
<person>
<name>Marc</name>
<cars>
<model>h20</model>
</cars>
</person>
</main>'
SELECT x.value('name[1]','nvarchar(max)') name,
x.value('cars[1]','nvarchar(max)') car
FROM @Data.nodes('//main/person') AS e(x)
-- Returns:
-- Name Car
------------------
-- Daniel y75b25
-- Marc h20
I would like to show:
Name Car
Daniel y75
Daniel b25
Marc h20
I tried in different way but I didn't find the good results!
Thanks.