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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Adding in SQL Server

Author  Topic 

jones_d
Yak Posting Veteran

61 Posts

Posted - 2005-01-19 : 15:32:35
Hi,

I have 2 databases (each SS2000) and I have loaded the exact same data into each. I have about 90 identical transactions and when I get the sum of the value of these transactions:
On one database I get -9.3132257461547852E-10
On the other database I get 1.3969838619232178E-9

Although the difference is very small it is causing problems in an application using this database.

Does anyone know why the difference might occur? The values of the transactions are exactly the same. Note I got the above figures using just the sum function in QA.

Any ideas or suggestions appreciated.

clarkbaker1964
Constraint Violating Yak Guru

428 Posts

Posted - 2005-01-19 : 18:46:04
Check the column properties size and precision

Go to Top of Page

jones_d
Yak Posting Veteran

61 Posts

Posted - 2005-01-20 : 05:07:02

Hi,

Both columns have a float data type.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-20 : 06:18:22
A float is an approximat data type so you should expect innacuracies.
It's may be due to the order it is doing the calculation.

Try checking the individual values to see if you can find differences

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jones_d
Yak Posting Veteran

61 Posts

Posted - 2005-01-20 : 06:59:04

Hi,

I have checked the individual entries and they are identical.

The problem is manifesting itself in a reporting tool, where we filter on all clients with a balance different than zero.

When this query is run against one database, a particular client is excluded because his balance (sum of transactions) is 0

However, in the other database the same client appears on the report because he has a balance of 0.00000000000004

Looking at the individual transactions, none of them has more than 2 decimal places but when you sum them, up to 10 figures can appear after the decimal point.

Is there any database setting controlling how the sum function works?
Go to Top of Page

jones_d
Yak Posting Veteran

61 Posts

Posted - 2005-01-20 : 12:52:01
Hi,

Just came across the following site, which gives more detail on the point that Nigel made earlier.

http://www.schemamania.org/jkl/booksonline/SQLBOL70/html/8_con_03_15.htm

Useful to know if you are deciding on data types for a table to store numeric financial data!
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-20 : 13:03:58
instead of sum(fld)
try
sum(convert(decimal(18,4),fld)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -