INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Why is zero value not recognized in SQL?

Why is zero value not recognized in SQL?

(OP)
I immediately apologize if this is the incorrect forum to post this thread.

I use Delphi6 on MS-Windows(Prof) in which I have the procedure below.

Even if the SUM of BALANCE, being the total of PLUS and MINUS values, amounts to '0'
TOTAL_ERROR does not see this as being '0' at LINE A in the procedure.

if dmStdAcc.PivotTbl1KeyOrigin.value = 'GL' then // Trial Balance is peculiar to the GL
begin // AND not a manual T/B
qryname1 := '''C:\h\StdAcc\' + IntToStr(dmStdAcc.PivotTbl1PNo.AsInteger) + '\GL'' t1, ''C:\h\StdAcc\PivotTbl1'' t2';
qryname2 := ('(t1.PNo = t2.PNo) AND(t1.PDate >= t2.AltStartDate) AND (t1.PDate <= t2.AsAtDate)');
with dmStdAcc.qryGLTBLeft do
begin
SQL.Clear;
SQL.Add('SELECT SUM (LBal)TOTAL_LEFT');
s:=format('FROM %s',[qryname1]);
SQL.Add (s);
s:=format('WHERE %s',[qryname2]);
SQL.Add (s);
Active := True;
dbtxFLBal.DataSource := dmStdAcc.dtsGLTBLeft;
end;

with dmStdAcc.qryGLTBRght do
begin
SQL.Clear;
SQL.Add('SELECT SUM (RBal)TOTAL_RIGHT');
s:=format('FROM %s',[qryname1]);
SQL.Add (s);
s:=format('WHERE %s',[qryname2]);
SQL.Add (s);
Active := True;
dbtxRBaL.DataSource := dmStdAcc.dtsGLTBRght;
end;

with dmStdAcc.qryGLTBError do
begin
SQL.Clear;
SQL.Add('SELECT SUM (BALANCE)TOTAL_ERROR');
s:=format('FROM %s',[qryname1]);
SQL.Add (s);
s:=format('WHERE %s',[qryname2]);
SQL.Add (s);
Active := True;
txtFTBError.DataSource := dmStdAcc.dtsGLTBError;
LINE A if dmStdAcc.qryGLTBError.FieldByName('TOTAL_ERROR').Value <> 0 then
Click;

Old Man Delphi

RE: Why is zero value not recognized in SQL?

considering your thread from last year thread102-1650604: What could this obscure result from a Query be? it seems that balance is a floating point.
Towerbase already explained the issue in that thread, a value close to 0 is not equal to 0 in the floating point world.

All you need to do is convert the floating point value to an integer value and then compare with 0.
So in your case:

CODE

...
if Round(dmStdAcc.qryGLTBError.FieldByName('TOTAL_ERROR').Value) <> 0 then
  Click; 


/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!

RE: Why is zero value not recognized in SQL?

To enhance your knowledge on floating point format :

http://rvelthuis.de/articles/articles-floats.html

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close