Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting Filtered Records

Status
Not open for further replies.

jerold

Programmer
Aug 30, 2000
52
PH
Could somebody help me how to count
records that are 1) filtered ; 2)deleted
 
hello

for filtered records you can say
use ('myfile')
count to xx for (condition of filteration)
as xx is a variable.
And for the deleted records:
set dele on
use ('myfile')
count to xx
=> xx will give the no. of undeleted records only
then
set dele off
count to yy
=> yy will give you all the records (undeleted+deleted)
the difference of (yy-xx) will give you the deleted records.

i hope this will work with you.

Suha

count
 
Hi,
there are several way to count record :
1. you can count record using COUNT FOR (your filter expression) if your view/table not filtered.
2. If your view already filtered (in local or remote view or filtered in cursor / Alias properties) you can use RECCOUNT(cAliasName) function.
 
set dele off
count to yy
=> yy will give you all the records (undeleted+deleted)


Reccount() will give the same but takes much less time.


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Why use a memvar?
use MyTable
count for (filter condition)
? _tally
set deleted off
count for deleted()
? _tally


David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
Using FILTER is a really great way to decrease performance. ;-) If your tables are really small, it may not matter. But if you have larger tables out on a server, you don't want to spend much time in a filtered condition.

You might try using the SELECT command with your filter conditions. This will create a cursor (or you could even make it a table) on the local drive. Using _TALLY on the next line will give you the count...

SELECT * FROM voters.dbf WHERE republican = .t. INTO CURSOR bush

nForBush = _TALLY && count of selected records

You've already been shown the DELETED() keyword, just be sure you've got DELETED set to 'off' first.

Warning: the above was written off the top of my head before I've finished my first cup of coffee! ;-)

Hank Castello
 
Hank, What about following:

SELECT count(*) * FROM voters.dbf WHERE republican = .t. INTO Array aResult

aResult contains number of records.

Above is the most efficient way. In addition, it is beneficial, sometimes, to create index by 'Deleted()' expression, because any query/filter with set deleted on will be optimized.



Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top