Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 

Go Back   XSL - XML - RSS Forums > XML General > SQL and XML

Tags:



Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2008, 03:50 AM
Loren Dummer
 
Posts: n/a

Default XQuery sum() function



I am having problems getting a sum from xml.

The following works and returns - 1150.75

DECLARE @Xml xml

SELECT @Xml = '<Charges>
<Charge>
<Amount>100.00</Amount>
</Charge>
<Charge>
<Amount>50.50</Amount>
</Charge>
<Charge>
<Amount>1000.25</Amount>
</Charge>
</Charges>'

SELECT @Xml.query('
sum( /Charges/Charge/Amount )
')



Now take the amount 1000.25 and change it to 1,000.25. It will return
150.5.

DECLARE @Xml xml

SELECT @Xml = '<Charges>
<Charge>
<Amount>100.00</Amount>
</Charge>
<Charge>
<Amount>50.50</Amount>
</Charge>
<Charge>
<Amount>1,000.25</Amount>
</Charge>
</Charges>'

SELECT @Xml.query('
sum( /Charges/Charge/Amount )
')


How can I get Sql Server to give me the correct sum of 1150.75 when some
values have commas in the values?

Thank-you in advance.


Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Contact Us -|- XSL - XML - RSS Forums -|- Archive -|- Top -|-Rules/Disclaimer-|-Help/Support -|-Advertise
© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
All times are GMT. The time now is 02:39 PM.
Style Developed by Epic Designz