sql server - Xml Shredding .Value Singleton -
i querying xml column in sql server 2012.
when moving path .value method results not returning element instances!
,c.value('(*/*/visitors/visitor/@name)[1]', 'nvarchar(50)') visitor ,c.value('(*/*/senders/sender/@name)[1]', 'nvarchar(50)') sender i using nodes method, wildcard killing performance
cross apply c.nodes('*') dd(d) outer apply d.nodes(visitors/visitor) ee(e) outer apply d.nodes('senders/sender') ff(f) now know can correct results (below) there way return element results using path in .value method without declaring 3 singletons, or .nodes method way of returning multiple element instances?
thanks!
,c.value('(*/*/visitors/visitor/@name)[1]', 'nvarchar(50)') visitor ,c.value('(*/*/visitors/visitor/@name)[2]', 'nvarchar(50)') visitor2 ,c.value('(*/*/visitors/visitor/@name)[3]', 'nvarchar(50)') visitor3 ,c.value('(*/*/senders/sender/@name)[1]', 'nvarchar(50)') sender ,c.value('(*/*/senders/sender/@name)[2]', 'nvarchar(50)') sender2 ,c.value('(*/*/senders/sender/@name)[3]', 'nvarchar(50)') sender3
the call .value() return single value definition.
if need enumerate list of nodes, use .nodes() - that's it's there for.
but please avoid using .nodes(*) - that's killer performance - need specific xpath in .nodes() call
Comments
Post a Comment