Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is zero value not recognized in SQL? 1

Status
Not open for further replies.

terrytype

Programmer
Jun 1, 2011
97
ZA
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;
[highlight #EDD400]LINE A[/highlight] if dmStdAcc.qryGLTBError.FieldByName('TOTAL_ERROR').Value <> 0 then
Click;

Old Man Delphi
 
considering your thread from last year thread102-1650604 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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top