TABLESUM Function
Syntax
Arguments
- tablename
The full drive, path, name, and extension of the table. If you omit the drive, path, and extension, Alpha Anywhere searches the directory of the current table. Character
- filter
A character filter expression that evaluates to a logical value. Selects records to sum.
- field
Any numeric value expresssed as a string, but typicaly an expression based on numeric or exponent numeric field(s) in the Lookup_Table.
Description
Returns the sum of fields of matching records in a specified table.
Discussion
Searches the specified tablename for one or more records that satisfy the specified Filter, and returns the sum of the values contained in the field. The Filter must return a logical value, either True (.T.) or False (.F.). For example, to choose all of the records in a table, use the logical constant ".T." as a filter. To choose only the records where the STATE field is equal to TN, use the filter "STATE = 'TN'". Note that the entire filter is always in quotations, and the character value, TN, is in single quotes. NOTE: If no records satisfy the filter, Alpha Anywhere returns a blank or zero value.
Assume that a department purchasing table ( PURCHASE ) contains the following records:
PURCHASE TABLE
MANAGER COST BILL_DATE PAID_UP
ANDRY 18500.00 01/01/2003 T
BROWN 49.95 02/01/2003 T
BROWN 12.99 04/01/2003 F
FARLEY 7995.00 03/01/2003 F
FARLEY 142.16 04/10/2003 T
FARLEY 423.00 05/10/2003 F
All Records
The following expression returns the sum of the values in the Cost field for all records in the Purchase table:
? TABLESUM("PURCHASE.DBF", ".T.", "COST")
= 27123.100000
Filter Using a Specific Character String
The following expression returns the sum of the values in the Cost field for all records in the Purchase table where "Farley" is the manager:
? TABLESUM("PURCHASE.DBF", "MANAGER = 'FARLEY'", "COST")
= 8560.160000
Filter Using a Character Variable
The following expression returns the sum of the values in the Cost field for all records in the Purchase table where the manager matches the character string previously assigned to the variable vManager.
? TABLESUM("PURCHASE.DBF", "Manager = '" + vManager + "' ", "COST")
= 62.940000 ' if vManager is "BROWN"
Filter Using a Specific Number
The following expression returns the sum of the values in the Cost field for all records in the Purchase table where the Cost is less than 5000.00.
? TABLESUM("PURCHASE.DBF", "Cost
= 628.100000
Filter Using a Numeric Variable
The following expression returns the sum of the values in the Cost field for all records in the Purchase table where the Cost is greater than whatever amount has been previously assigned to the numeric variable vCost.
? TABLESUM("PURCHASE.DBF","Cost > " + vCost,"COST")
= 26495.000000 ' if vCost = 1000.00
Filter Using a Specific Date Value
The following expression returns the sum of the values in the Cost field for all records in the Purchase table where the Bill_Date is equal to or later than February 1, 2003.
? TABLESUM("PURCHASE.DBF","BILL_DATE >= {02/01/2003}", "COST")
= 8623.100000
Filter Using Date Variables
The following expression returns the sum of the values in the Cost field for all records in the Purchase table where the Bill_Date is equal to or later than the date previously assigned to vBeginDate AND equal to or later than the date previously assigned to vEndDate :
? TABLESUM("PURCHASE.DBF", "BETWEEN(BILL_DATE,{" + DTOC(vBeginDate) + "},{" + DTOC(vEndDate) + "})", "COST")
= 26544.950000 ' if vBeginDate is 01/01/2003 and vEndDate is 03/31/2003
Filter Using Logical Variables
The following expression returns the sum of the values in the Cost field for all records in the Purchase table where Paid_Up is true:
? TABLESUM("PURCHASE.DBF", "PAID_UP", "COST")
= 18692.110000
While this expression returns the sum of the values in the Cost field for all records in the Purchase table where Paid_Up is not true:
? TABLESUM("PURCHASE.DBF", ".NOT. PAID_UP", "COST")
= 8430.990000See Also