Knowledge Base |

# How to determine the number of records that are returned by a SELECT-SQL statement in Visual FoxPro

Article ID: 113808

Article Last Modified on 2/12/2007

APPLIES TO

- Microsoft Visual FoxPro 3.0 Standard Edition
- Microsoft Visual FoxPro 6.0 Professional Edition
- Microsoft Visual FoxPro 7.0 Professional Edition
- Microsoft Visual FoxPro 8.0 Professional Edition
- Microsoft Visual FoxPro 9.0 Professional Edition

This article was previously published under Q113808

## SUMMARY

In Microsoft Visual FoxPro You can create generic SELECT-SQL statements that programmatically produce result sets of records to be output for viewing in a number of ways. However, in certain instances, a SELECT-SQL statement may not produce any records in the query based on the SELECT-SQL criteria provided.
To avoid having a program act upon an empty result, the system variable _TALLY can be evaluated immediately after a query has been executed in order to determine the number of records that have been selected. For more information about _TALLY, see the code example below.

## MORE INFORMATION

The following rudimentary example illustrates the usage of the _TALLY system variable. Copy the code into a program (.PRG) file, run the program file, and then follow the prompts that appear on the Visual FoxPro desktop.

       *
       *
       SET STATUS OFF && SET STATUS BAR OFF in FoxPro for Windows
       fyl = GETFILE('DBF','Choose a table:')
       USE (fyl)
       LIST STRUCTURE
       USE
       ACCEPT 'Enter field list, separated by commas (or ENTER for all):' ;
          TO flds
       IF EMPTY(flds)
          flds='*'
       ENDIF
       ?
       ACCEPT 'Enter conditions (or ENTER for none) ' TO cond
       IF EMPTY(cond)
          cond=''
       ELSE
          cond='WHERE '+cond
       ENDIF

       SELECT &flds FROM (fyl) &cond INTO CURSOR query NOCONSOLE

       IF _TALLY>0
          BROWSE
       ELSE
          WAIT WINDOW 'No matching records found...'
       ENDIF

Additional query words: VFoxWin FoxMac FoxDos FoxWin null blank

Keywords: kbcode KB113808