sum some xml nodes values in sql server 2008

前端 未结 4 726
傲寒
傲寒 2021-01-13 19:24

Please consider this XML:


    10 
    20 
    

        
4条回答
  •  星月不相逢
    2021-01-13 19:41

    select @xml.value('sum(/Parent[@ID = "p"]/Child)', 'float') as Sum
    

    The use of float protects against there being no Parent with that ID. You can then cast this result to int.

提交回复
热议问题