Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sum of data

Author  Topic 

BendJoe
Posting Yak Master

128 Posts

Posted - 2010-05-26 : 16:30:38
A----------------B------C-----
-208.5100 -10.43 -218.94
29.4800 1.48 30.96
150.8400 7.55 158.39
208.5100 10.43 218.94
269.2900 13.47 282.76
732.6800 36.63 769.31
2891.3500 144.57 3035.92
select sum(A),sum(B),sum(C) from Table
the sum I am getting is this.
12220.9200 611.10 12832.02
How can I get the correct result.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-26 : 16:51:58
Works fine for me:

CREATE TABLE #t (A decimal(18,4), B decimal(18,4), C decimal(18,4))

INSERT INTO #t VALUES(-208.5100, -10.43, -218.94)
INSERT INTO #t VALUES(29.4800, 1.48, 30.96)
INSERT INTO #t VALUES(150.8400, 7.55, 158.39)
INSERT INTO #t VALUES(208.5100, 10.43, 218.94)
INSERT INTO #t VALUES(269.2900, 13.47, 282.76)
INSERT INTO #t VALUES(732.6800, 36.63, 769.31)
INSERT INTO #t VALUES(2891.3500, 144.57, 3035.92)

SELECT SUM(A), SUM(B), SUM(C)
FROM #t

DROP TABLE #t


Output:

4073.6400 203.7000 4277.3400


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -