How to get XML attributes from XML with an unknown number of rows

francisand

New Member
I have the following query that allows me to get xml data from ONE row of xml from a specified column.However, Product can have 1 UPC child, or a lot.How can I alter my query to return all the existing children of Product?\[code\]DECLARE @MyXML XMLSET @MyXML = (SELECT ProductsXML FROM Products WHERE ProductId= 1)SELECT a.b.value('Product[1]/UPC[1]/@upccode','DATE') as UPC, a.b.value('Product[1]/UPC[1]/@dateadded','DATE') as DateAdded FROM @MyXML.nodes('xml')a(b) \[/code\]
 
Back
Top