This is what the column xml looks like
<Attributes>
<ProductAttribute ID="9">
<ProductAttributeValue>
<Value>21</Value>
</ProductAttributeValue>
</ProductAttribute>
<ProductAttribute ID="10">
<ProductAttributeValue>
<Value>25</Value>
</ProductAttributeValue>
</ProductAttribute>
</Attributes>
And i want to return it like
ProductAttribute ProductAttributeValue
--------------------------------------------------
9 21
10 25
My query now looks like this
SELECT
ProductId as ProductId,
ProductAttributeNode.value('(@ID)', 'int') as ProductAttributeMappingId,
ProductAttributeNode.value('(//ProductAttributeValue[1]/Value/text())[1]', 'int') as ProductAttributeValueId
FROM
(
SELECT
Id,
ProductId,
CAST(AttributesXml as XML) as AttributesXml,
Sku
FROM
ProductAttributeCombination
) AS PAC
CROSS APPLY AttributesXml.nodes('//Attributes/ProductAttribute') as T1(ProductAttributeNode)
And what i get back is
ProductAttribute ProductAttributeValue
--------------------------------------------------
9 21
10 21 <--- not 25
//is a deep search* finding each and any node with the given name. The XML will be the whole lot, but - coming out of nodes - with a relative position. That's why you can reach to a parent node with... The given answer is correct and would work even without the./. Your<ProductAttributeValue>is right below the current node.