Subject RE: [IBO] Aggregate functions of a Live TIB_Grid?
Author Claudio Valderrama C.
> -----Original Message-----
> From: Hug [mailto:hugosan@...]
> Sent: Lunes 12 de Marzo de 2001 18:12
>
> I have a TIB_Grid for insert and update records, and I would show
> on the same form a virtual, calculated field (read-only, as a
> simple Label), that accumulates the total amount of all records.
> For example:
> TABLE SALES (
> ID SMALLINT (with generator) PRIMARY KEY
> ,ITEM_ID SMALLINT
> ,QUANTITY DOUBLE PRECISION
> ,PRIZE DOUBLE PRECISION)
>
> It's to say, I need something like
> SELECT SUM(QUANTITY*PRIZE)
> FROM SALES,
> and everytime table SALES changes, it calculates again

It's very easy if you do it by brute force: in the AfterPost event for your
dataset, simply loop through BufferFields (see Buffer* properties) and get
the sum of your Quantity*Prize in an edit box. This will work because
AfterPost is triggered in IBO even for Delete operations. One caveat: if you
edit later the invoice's items, BufferEof may not reflect the end of the
query's results but the end of the buffer, so you'll want to call FetchAll
before you edit the items of an invoice that existed previously. (While
inserting a new invoice, there should be no problem.)
I don't understand your table. Usually I break an invoice into header table
and the sold items table. Is ID_SMALLINT a FK from the master invoice table
or what?

C.