I want to sum the quantity of all products/Product/Quantity after the value has been rounded.
My XML looks like:
<Products>
<Product>
<ExternalId>116511</ExternalId>
<Price>2.99 </Price>
<Quantity>1.500 </Quantity>
<NetValue>4.08 </NetValue>
</Product>
<Product>
<ExternalId>116510</ExternalId>
<Price>2.99 </Price>
<Quantity>1.500 </Quantity>
<NetValue>4.08 </NetValue>
</Product>
<Product>
<ExternalId>116512</ExternalId>
<Price>1.99 </Price>
<Quantity>10.000 </Quantity>
<NetValue>18.09 </NetValue>
</Product>
<Product>
<ExternalId>329245</ExternalId>
<Price>59.99 </Price>
<Quantity>1.000 </Quantity>
<NetValue>54.53 </NetValue>
</Product>
</Products>
The above XML is stored in x with column of Data.
I've tried using xQuery sum and round functions like so but this only rounds and sums the first instance of Quantity (i.e. sum(round(1.5)) = 2) :
SELECT Data.Value('(Products/Product/ExternalId/text()[1]', 'float') AS ExternalId,
x.Data.value('sum(round((/row/Products[1]/Product/Quantity)[1]))', 'float') Trn_Quantity
FROM x