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 problem

Author  Topic 

ianwaters
Starting Member

2 Posts

Posted - 2007-09-19 : 04:54:28
Hi im using SQL server 2000 sp4

i have a table with a column of type float called [veh yrs]

none of the entries are null but when i run:

select sum([veh yrs]) as [veh yrs sum] from [testtable]

sum gives an incorrect value.

[testtable]
[veh yrs]
-0.93150684931506844
1.0027397260273974

[veh yrs sum]
7.1232876712328919E-2

why is [veh yrs sum] 7.1232 ???

Many Thanks for your help

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-09-19 : 04:59:22
This is formatting problem. Use Convert() to convert result to NUMERIC data type

Select Convert(Numeric(25,6), sum([veh yrs])) as [veh yrs sum] from [testtable]


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-19 : 05:01:00
Because it is using scientific notation.
The E-2 at the very end denotes that the number 7.1232E-2 stands for

-2
7.1232 * 10
which is 0.071232876712328919



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ianwaters
Starting Member

2 Posts

Posted - 2007-09-19 : 05:09:22

Thanks guys you have saved me a couple of hours
searching!

i hadnt tried CONVERT but it works

Thanks again!
Go to Top of Page
   

- Advertisement -