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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wanting it to Not Round Off

Status
Not open for further replies.

NewToProgramming

Technical User
Jun 24, 2003
31
0
0
US
I have a query that pulls numbers from a table field. These numbers are not whole numbers, they have decimals. When I use the query to gather up those numbers and add them together, it rounds them off to the whole number.
How do you stop that from happening?
 
Oh, here is the code to help with any questions.
Query := TQuery.Create( nil );
I := 1;
R := 0;
Query.DataBaseName := Table1.DataBaseName;
Query.SQL.Add( 'SELECT (field) as whatever from db.Db' );
try
Query.Open;
Query.First;
while not Query.Eof and (i<=10) do
begin
R := R + Query.FieldByName('Whatever').AsInteger ;
Query.Next;
Inc(i);
Form3.Edit1.Text := FormatFloat(FormatSpec, R div 10);
end;
finally
Query.Free;
end;
Result := True;
end;
 
use

Code:
Query.SQL.Add( 'SELECT sum(field) as whatever from db.Db' );

and skip the loop in your code.

The data type problem has to do with client language you are using and is not a SQL issue.
 
When I did that it sumed up all my records. I only want it to sum up the lowest 10.
 
Oh, I missed that part. Most DBMS has some facility for limiting the number of rows returned.

E.g.

top in SQL server and Access

limit in Mysql and Progress

first in Interbase/Firebird

olap functions

Which dbms are you using?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top