Solved

SUM is incorrect when performing on Float column in DB, How can I fix this?

Posted on 2013-12-12
4
318 Views
Last Modified: 2013-12-12
Current:
FloatCol with float for datatype
SumofFloatCol

Sum of Float Col is way off how can I sum this column with the values in floatCol

FloatCol
102.8
22.8
68.3
656.2
755.4
382.8
736.5
728.9
163.9
0.1

SumOfFloatCol
139608.36
Using this query
SELECT sum(FloatCol)
From Table1
0
Comment
Question by:rhservan
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
Simone B earned 250 total points
ID: 39714720
Your query is correct. Do you only have 10 rows in your table?
0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 39714728
Just for kicks and giggles, do a 'SELECT * FROM Table1' and verify that there are only 10 rows in it, with floatcol values as you posted above.
0
 

Author Comment

by:rhservan
ID: 39714905
So I take it the SUM aspect works the same on float as SUM on any other legitimate datatype.

1+1=2. I thought maybe float was not working correctly with SUM.    I get this.
--------------------------------------------------------------------------------------------------------------------------------

So using another scenario in an SSRS column in a Tablix:

Col_1
102.8
22.8
68.3
656.2
755.4
382.8
736.5
728.9
163.9
0.1

how would I SUM this column in the last row.

Currently Using this query
SELECT sum(FloatCol)
From Table1  
Seems to give me the total of all the rows, about 85,000,  instead of just the rows returned from the query which is somewhere like 3,600.
0
 
LVL 11

Expert Comment

by:Simone B
ID: 39715283
Use the same field, and just put it in the summary row. It will do the sum for you automatically. You don't have to have a separate query.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Slow Connectivity over ODBC 8 36
query execution hang 5 31
SQL Server - Set Value of Multiple Fields in One Query 10 25
SQL Server 2015 Restore - doing it right 2 14
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question