Hi Brenda,
Because with SELECT TOP N .. ORDER BY ...,
if record N have duplicate records respect to the ORDER BY ... rule,
the SELECT put all the duplicate on the result cursor, then _TALLY can to be
to exceed N.
But a solution exist.
If you append ,0 [ASC | DESC] to the ORDER BY clause, it is like to ,RECNO() [ASC | DESC] and this force ( RECNO() is unique ) the max RECCOUNT of the result table to N.This behaviour is not documented, but it is not casual because -1 or other costant
are implemented like order by 1.
Then ( DELETE REST is not necessary):
SELECT TOP 100 * FROM myTable ORDER BY 0 INTO CURSOR myResult
SELECT TOP 100 * FROM myTable ORDER BY 0 DESC INTO CURSOR myResult
Attention, on VFP, ORDER BY is not optimized,
then, before return 100 records,
VFP build all filtered records ( WHERE results )
and then reorder
and then return TOP records.
For big filtered tables, a low level query
SELECT ... WHERE .F. INTO CURSOR myResult READWRITE
SCAN WHILE RECCOUNT('myResult')<=N
....
INSERT INTO myResult ...
ENDSCAN
can to be much more faster.
FABIO