1

Topic: Help with request

declare @x xml = ' <books>
<book id = "52F84494-51ED-4FAA-9B3E-6B0A66D1D103" number = "10"/>
<author lname = "Surname" fname = "Name"/>
</books>
<books>
<book id = "EA07129F-66F9-4C05-B7BD-242D641F9D74" number = "11"/>
<author lname = "Familija1" fname = "Imja1"/>
</books>'
select c.value (' @id ', ' varchar (50) ')
from @x.nodes (' books/book ') as t (c)

How to deduce id and corresponding  the author?
1,2,3
52F84494-51ED-4FAA-9B3E-6B0A66D1D103,,
EA07129F-66F9-4C05-B7BD-242D641F9D74,1,1

2

Re: Help with request

marvel;

select
c.value (' book [1] / @id ', ' varchar (50) ')
, c.value (' author [1] / @lname ', ' varchar (50) ')
, c.value (' author [1] / @fname ', ' varchar (50) ')
from @x.nodes (' books') as t (c)

Or

select
b. N.value (' @id ', ' varchar (50) ')
, a. N.value (' @lname ', ' varchar (50) ')
, a. N.value (' @fname ', ' varchar (50) ')
from @x.nodes (/books ') as t (c)
cross apply t.c.nodes (' book ') as b (N)
cross apply t.c.nodes (' author ') as a (N)

3

Re: Help with request

Ilnur26;
Thanks