Board index » delphi » SUM(), AVG(), COUNT()

SUM(), AVG(), COUNT()

Hi there,

how can I retrieve the value returned from a statement with an aggregate
function like

select sum(tablefield) from tablename

to display it e.g. in a messagebox? I could open a query which would include
one record with the value, but is this a smart way?

What about the INTO clause with a variable?

Thanx in advance..

Guido Bertsche (berts...@quantum.de)

 

Re:SUM(), AVG(), COUNT()


G'day Guido,

Try this (untested code):

        Query1.SQL.Add('select count(field1) as field2 from "table.db"');
        Query1.Open;
        Query1.First;
        ShowMessage('Value=' + Query1.FieldByName('field2').AsString);

Hope this helps,

M@

Quote
Guido Bertsche wrote:

> Hi there,

> how can I retrieve the value returned from a statement with an aggregate
> function like

> select sum(tablefield) from tablename

Other Threads