_Tally
This system variable tells you how many records were processed by the last command that affects it. The most common use for _TALLY is to check how many records were returned by a SQL-SELECT, but it actually works with many Xbase commands and the other SQL commands.
Usage |
nNumAffected = _TALLY |
Append From |
Delete |
Replace |
However, there's one real oddity on this list. _TALLY after REINDEX contains the number of records for which the last tag indexed applies. If you have filtered tags (indexes using a FOR clause), _TALLY returns the number of records contained in the last index. "Last" here refers to the creation order of the tags, since they're re-created in the same order. This isn't really a big problem since we suggest you never use REINDEX anyway. |
In VFP 3 and VFP 5, when TALK is OFF, INDEX and REINDEX don't update _TALLY. This bug is fixed in VFP 6. |
Example |
SELECT First_Name, Last_Name FROM Employee ; WHERE MONTH(Birth_Date)=MONTH(DATE()) ; INTO ARRAY aThisMonth * Check if any records met the criteria. IF _TALLY=0 * If not, create the array with blank values. DIMENSION aThisMonth[1,2] aThisMonth = "" ENDIF |
USE Employee COUNT FOR MONTH(Birth_Date)=MONTH(DATE()) WAIT WINDOW ; LTRIM(STR(_TALLY))+" employees have birthdays this month"Do watch out for one thing with _TALLY. Because so many commands affect it, it's important to grab the value right away if you want to keep using it. Otherwise, you run the risk that a later command will overwrite the value.
See Also |
Append From, Average, Blank, Calculate, Copy To, Copy To Array, Count, Delete, Delete-SQL, Export, Index, Join, Pack, Recall, Reindex, Replace, Replace From Array, Select-SQL, Sort, Sum, Total, Update, Update-SQL |