how to add summary field to a table?

how to add summary field to a table?

Post by shotokan9 » Mon, 27 Feb 2006 17:21:23


i have this table struct:

id string
name string
gross real
net real
tax real


now i want to add a field like calculated field to have sum(...) of
each real type fields. is it available in a table component or i have
to make a function manually?
 
 
 

how to add summary field to a table?

Post by Dan » Thu, 02 Mar 2006 08:52:34

On 26 Feb 2006 00:21:23 -0800, "shotokan99" < XXXX@XXXXX.COM >



You can add a field object to a TDataSet. Then define the new field as
Calculated as the sum of one of the underlying table fields. The sum
then appears in the dataset. Be careful to keep in mind that a sum
field in a multi-row dataset doesn't make much sense. Check out the
SQL SUM and COUNT functions, for example. They make sense only if the
query returns a single row (or a GROUP of different sums). This means
getting a list of values and a sum of them to appear at the bottom
means either two queries or do the summation in code.

Check out these topics in localsql.hlp.

BTW, using reals for currency calculations can cause problems due to
rounding errors. Look at using currency or integers. I'm not familiar
with all the problems and solutions, but I'm sure someone here has the
guidelines for you. Just ask.

hth,
Dan