Counts table records.

COUNT   [Scope] [FOR lExpression1] [WHILE lExpression2]   [TO VarName]
   [NOOPTIMIZE]

Parameters

Scope

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 Scope Clauses.

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, see SET OPTIMIZE Command and Using Rushmore Query Optimization to Speed Data Access.

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.

NOOPTIMIZE

Disables Rushmore optimization of COUNT. For more information see SET OPTIMIZE Command and Using Rushmore Query Optimization to Speed Data Access.

Expand imageRemarks

Expand imageExample

Expand imageSee Also