Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread SQL Question? No error - wrong result?
Mon, Sep 24 2007 3:22 AMPermanent Link

Dave Bailey
Hi,

I have a table with 4 Float Fields eg: a,b,c,d

d is entered by the user but is the result of a+b+c

I wanted to create an SQL to filter out all records where d<>a+b+c

I used SELECT * FROM MyTable WHERE (a+b+c)<>d

But the result included records where a+b+c=d as well?

Tested the same on Access and no problem. Maybe it is something I am doing wrong?
Thanks
Mon, Sep 24 2007 4:06 AMPermanent Link

Eryk Bottomley
Dave,

> I have a table with 4 Float Fields eg: a,b,c,d
>
> d is entered by the user but is the result of a+b+c
>
> I wanted to create an SQL to filter out all records where d<>a+b+c
>
> I used SELECT * FROM MyTable WHERE (a+b+c)<>d


Never use direct equality tests on floats like that.

> But the result included records where a+b+c=d as well?


Try "WHERE ABS((a+b+c)-d) > 0.01" ...or whatever level of precision
makes sense in the context of your app.

Eryk

PS: You might want to read up on BCD fields - they may be more
appropriate than floats if you are doing stuff like this.
Mon, Sep 24 2007 4:08 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Dave


Float fields are notorious for this. Its a case of what you see is not necessarily what you get Smiley You'll need to round each field in some way. Then again Tim may need to make sure the results for a float field are only returned to the precision specified. I'm not sure which it should be in ElevateDB, in DBISAM it was definitely your responsibility.

Roy Lambert
Mon, Sep 24 2007 6:42 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Roy,

<< Float fields are notorious for this. Its a case of what you see is not
necessarily what you get Smiley You'll need to round each field in some way.
Then again Tim may need to make sure the results for a float field are only
returned to the precision specified. I'm not sure which it should be in
ElevateDB, in DBISAM it was definitely your responsibility. >>

ElevateDB is the same as DBISAM in this regard.

--
Tim Young
Elevate Software
www.elevatesoft.com

Mon, Sep 24 2007 6:43 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Eryk,

<< PS: You might want to read up on BCD fields - they may be more
appropriate than floats if you are doing stuff like this. >>

DECIMAL is the proper term with ElevateDB. Smiley

http://www.elevatesoft.com/edb1sql_exact_numeric_types.htm

--
Tim Young
Elevate Software
www.elevatesoft.com

Image