I am using Delphi 5, and would like to know how to calculate the sum of a column in a table. I have got a grid and done this 'sum:=DBGrid2.Columns[6].Field.value;' but all this does is do the sum for the highlighted row?
Anybody help
Regards Pete
Whats the database back-end ?
You could use an SQL Command with the SUM(Field1) function to acquire the total.
Alternatively (but not ideal) you could run code like :
tpRunTotal := 0;
with Table1 do
begin
First;
while not EOF do
begin
tpRunTotal := tpRunTotal + Table1Field1.AsFloat;
Next;
end; // while not EOF
end; // with Table1 do
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.