Counts table records.
Specifies a range of records to be included in the count. The default scope for COUNT is ALL records.
The scope clauses are: ALL, NEXT nRecords, RECORD nRecordNumber, and REST. Commands that include Scope operate only on the table in the active work area.
For more information on scope clauses, see.
- FOR lExpression1
Specifies that only the records that satisfy the logical condition lExpression1 are counted. Including FOR lets you conditionally count records, filtering out undesired records.
Rushmore Query Optimization will optimize a COUNT FOR query if lExpression1 is an optimizable expression. For best performance, use an optimizable expression in the FOR clause.
For more information on optimizable expressions, seeand .
- WHILE lExpression2
Specifies a condition whereby records are counted for as long as the logical expression lExpression2 evaluates to True (.T.).
- TO VarName
Specifies the variable or array to which the record count is stored. If the variable you specify doesn't exist, Visual FoxPro creates it.
Disables Rushmore optimization of COUNT. For more information seeand .
The following example counts and displays the number of customers in Paris.
CLOSE DATABASES OPEN DATABASE (HOME(2) + 'Data\testdata') USE customer && Opens Customer table CLEAR COUNT FOR UPPER(city) = 'PARIS' DISPLAY FIELDS company, contact FOR UPPER(city) = 'PARIS'