From xml in SQL Server, get next sibling value

carrotter

New Member
I've got a table that looks like this:\[code\]CREATE TABLE CustomerXmlData(CustomerId int,CustomerData xml)\[/code\]The CustomerId links to the main customer table and the CustomerData is an xml document that looks like this\[code\]<Person> <Product> <Name>ABC</Name> <Value>500</Value> </Product> <Product> <Name>XYZ</Name> <Value>600</Value> </Product></Person>\[/code\]There are several hundred thousand such rows. In pseudocode, what I want to do is "Find the average \[code\]Value\[/code\] of \[code\]Product\[/code\] where \[code\]Name\[/code\] = 'XYZ'".I know how to get values out based on element attributes or based on having a parent that is unique in the document, but neither of those is any use in this situation. I can't find anything that will let me locate the \[code\]Name\[/code\] that I want and then get the value of the next sibling.I can use \[code\]FOR XML\[/code\] and create an edge table, but would I then have to loop through that with a cursor? I'm hoping for a more efficient solution.
 
Back
Top