I ask a question about sum node\'s values:
sum some xml nodes values in sql server 2008
Please consider this code:
Declare @xml xml
set @xml
Try this one -
DECLARE @xml XML
SELECT @xml='
1000000000
234650
0
'
SELECT @xml.value('sum(for $r in /Parent[@ID="p"]/Child return xs:int($r))', 'bigint')
UPDATE:
DECLARE @xml XML
SELECT @xml='
100000000000000
234650
0
'
SELECT @xml.value('sum(for $r in /Parent[@ID="p"]/Child return xs:decimal($r))', 'bigint')
UPDATE 2:
DECLARE @xml XML
SELECT @xml='
100000000000000.6
234650
0
'
SELECT @xml.value('sum(for $r in /Parent[@ID="p"]/Child return xs:decimal($r))', 'decimal(18,2)')