Subject | Re: [IBO] aggregate fields? Persistant fields? |
---|---|
Author | Eddie Bush |
Post date | 2004-03-23T01:19:24Z |
Assuming a "detail data-set" with a FK to the master named MasterId and a field named myField that is an line-item total:
SELECT
T.MasterId,
Sum(T.myField) as TotalAmt
FROM
TheTable T
WHERE
T.MasterId = :MastId
GROUP BY
T.MasterId;
I think that's what you're looking for. This will go through the table "The Table" (this is the detail data-set), and sum all the "myField" fields having a "MasterId" field determined by the :MastId parameter. You could poke this into a TIB_Query and exec/open/activate it to retrieve the sum, or you could iterate over it and sum it yourself.
Is that what you're looking for? This is a pretty basic query. If that's what you're looking for you might do well to find an SQL book and study it some - there's a lot of power in SQL.
Notice I renamed the sum to TotalAmt (by saying 'as TotalAmt') so that it can more easily be referenced through the query ...
HTH,
Eddie
SELECT
T.MasterId,
Sum(T.myField) as TotalAmt
FROM
TheTable T
WHERE
T.MasterId = :MastId
GROUP BY
T.MasterId;
I think that's what you're looking for. This will go through the table "The Table" (this is the detail data-set), and sum all the "myField" fields having a "MasterId" field determined by the :MastId parameter. You could poke this into a TIB_Query and exec/open/activate it to retrieve the sum, or you could iterate over it and sum it yourself.
Is that what you're looking for? This is a pretty basic query. If that's what you're looking for you might do well to find an SQL book and study it some - there's a lot of power in SQL.
Notice I renamed the sum to TotalAmt (by saying 'as TotalAmt') so that it can more easily be referenced through the query ...
HTH,
Eddie
----- Original Message -----
From: delphi_acctg
To: IBObjects@yahoogroups.com
Sent: Monday, March 22, 2004 7:18 AM
Subject: Re: [IBO] aggregate fields? Persistant fields?
Paul:
I think I didn't explain very well. <g>
The aggregated field I am referring to is, in the ClientDataSet. I
can create a new field and set it's type to Aggregated and set it's
expression to sum(myField) and it will total all records and give me
a total. The SQL Sum(myfield) will not do that, correct?
Thanks.
---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0403-14, 03/18/2004
Tested on: 3/22/2004 7:19:25 PM
avast! - copyright (c) 2000-2004 ALWIL Software.
http://www.avast.com
[Non-text portions of this message have been removed]