|
View previous topic :: View next topic
|
| Author |
Message |
chandraBE
New User
Joined: 02 Feb 2010 Posts: 44 Location: Bangalore
|
|
|
|
I am running a query to get the totals for the values of few columns. But I am getting slight discrepancy in the results in the below queries.
The Query I have used
SELECT COUNT(*),
SUM(FLOAT(AM_PRINCIPLE_CASH))
FROM TRANSACT A, TRAN_REF B
WHERE (A.IN_HIST_PEND = 'H')
AND A.ID_TRAN = B.ID_TRAN
AND B.CD_BUS_SYS = 'ABC'
AND A.DT_ACC_TRAN = '2010-07-22';
The result I have got is
59348 +0.9419550453190383E+09
where AM_PRINCIPLE_CASH defined as DECIMAL(18, 6).
Then I have tried to optimize the query to by negating the index.
SELECT COUNT(*),
SUM(FLOAT(AM_PRINCIPLE_CASH))
FROM TRANSACT A, TRAN_REF B
WHERE (A.IN_HIST_PEND = 'H' OR 0=1)
AND A.ID_TRAN = B.ID_TRAN
AND B.CD_BUS_SYS = 'ABC'
AND A.DT_ACC_TRAN = '2010-07-22';
Now the result I have got is
59348 +0.9419550453192099E+09
How ever when I removed the FLOAT in the query then I have got the consistent result in the both queries. But value was for the column was 0000941955045.320000. (This should be the correct value).
But I am not able to understand that even though I have not changed anything much in the query its giving me slight difference when I used FLOAT. Can some one help me to understand why the negating the index can cause this problem? |
|
| Back to top |
|
 |
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
the access path changes so the order in which all the rows come is different.
With intermediate rounding/accuracy loss the order of terms in a sum is important. |
|
| Back to top |
|
 |
dick scherrer
Moderator Emeritus

Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
When FLOAT is used, accuracy is reduced. . . This works well for a moon-shot, but not so well for business accounting.
Why would there be a reason to use FLOAT when dealing with money? Or units shipped. . . Or any other amount or quantity?
Suggest non-float be used for these. . .
Possibly, there is something i misunderstand. . . |
|
| Back to top |
|
 |
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
| dick scherrer wrote: |
Hello,
When FLOAT is used, accuracy is reduced. . . This works well for a moon-shot, but not so well for business accounting.
|
And even with moonshots there are inflight course corrections. |
|
| Back to top |
|
 |
chandraBE
New User
Joined: 02 Feb 2010 Posts: 44 Location: Bangalore
|
|
|
|
| Thanks GuyC and Dick Scherrer for your quick replies. That was pretty much useful information. |
|
| Back to top |
|
 |
|
|