Actually usually it's faster to shred XML from parent to child using apply
, like this:
select
t.c.value('@id','int') as TransId,
i.c.value('@id','int') as ItemId,
i.c.value('(price/text())[1]', 'int') as PriceId
from @xml.nodes('transaction') as t(c)
outer apply t.c.nodes('item') as i(c)
order by TransId, ItemID