sql - Xquery SUM after value has been rounded -


i want sum quantity of products/product/quantity after 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 stored in x column of data.

i've tried using xquery sum , round functions rounds , sums first instance of quantity (i.e. sum(round(1.5)) = 2) :

select data.value('(products/product/externalid/text()[1]', 'float') externalid, x.data.value('sum(round((/row/products[1]/product/quantity)[1]))', 'float') trn_quantity x 

you can try using xquery for loop construct round individual quantity , pass them sum(), :

select      data.value('(products/product/externalid/text()[1]) externalid,     x.data.value('         sum(             $quantity in /products[1]/product/quantity             return round($quantity)         )     ', 'float') trn_quantity x 

quick test here : http://sqlfiddle.com/#!3/9eecb7/7351


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -