Board index » delphi » Calculated Totals of Calculated Totals

Calculated Totals of Calculated Totals

Hello,

I need to calculate totals for a master-child-grandchild relationship. The total value in the
master table is the total of values for the child table and the values in the child table are the
total values for the grandchild table.

Can anyone tell me the best/safest way of doing this without getting circular.

Warren

 

Re:Calculated Totals of Calculated Totals


Quote
>>I need to calculate totals for a master-child-grandchild relationship.

If the sum value is physicaly stored in the master table,  then
I'd place code to do the sum from the OnAfterPost event of the detail.

If the sum is only a calcualted field, then in addition to the OnAfterPost event
for the detail, I'd do the sum from the master datasource's  OnDataChange event...

The sum could be done either by:

1. instantiating a TTable and scaning  through that TTable's records to do the sum

2.  Using a TQuery and SQL to get the sum ie:

SELECT Sum(ExtdCost)
WHERE OrderNo = 1234

===
Bill

Re:Calculated Totals of Calculated Totals


An addition to what Bill has already told you.  Be very careful of the fact
that a master table's OnCalcFields event fires _before_ the link to the
detail table is updated. Therefore, if you try to create a calculated field
for the master that scans the detail to sum a value you must use a second
TTable and call SetRange to see the correct set of detail records.

--
Bill

Re:Calculated Totals of Calculated Totals


In article <6degis$ft...@forums.borland.com>,
        "Bill Todd (TeamB)" <bill_todd.nos...@compuserv.com> wrote:

Quote
>Be very careful of the fact that a master table's OnCalcFields event fires _before_ the link to
>the detail table is updated. Therefore, if you try to create a calculated field
>for the master that scans the detail to sum a value you must use a second
>TTable and call SetRange to see the correct set of detail records.

I am only using the calculated fields in the master and detail table to perform calculations on
fields within the same table. I have three tables linked: master-detail-subdetail, and I am using
after post and after delete events to update the calculated totals in the two detail tables. The
subdetail table updates a total in the detail table ok, but I have been having problems with
getting the detail to total and update the master.  Something somewhere is causing a post event in
the detail table during the update which causes a table already locked by session error.

Warren.

Re:Calculated Totals of Calculated Totals


Try scanning a second TTable object to compute the totals.

--
Bill

(TeamB cannot answer questions received via email.)
(To contact me for any other reason remove nospam from my address)

Other Threads