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!

How do i determine the number of rows returned from a TQuery?

Status
Not open for further replies.

ndolson

Programmer
May 3, 2001
9
US
Can anyone tell me how to determine the number of rows returned from a TQuery?
 
I think it's as simple as using Query1.RecordCount.
If you're only interested in the count then maybe run a different SQL in your TQuery - something like 'SELECT COUNT(Field1) RecordCount FROM Table1' and then read the value of Query1RecordCount.AsInteger.
Either way should work - the second will probably be more efficient if it is ONLY the count you are interested in.
Hope that this helps.
Steve
 
The property RecordCount Steven van Els
SAvanEls@cq-link.sr
 
But prior to calling RecordCount you need to call Last and then First methods of a query.

--- markus
 
What am I missing here ?
Why the need to use Last and First calls ?

Steve
 
McMerfy I think that applies to paradox tables, with interbase you only need to open or execute the query. Steven van Els
SAvanEls@cq-link.sr
 
Nope, in interbase not all records are fetched after opening a query too, so RecordCount would give a wrong result. StevenK a call to Last method fetches all records into memory, a call to First returns cursor to the first record as if you've just opened the query (you can call to FetchAll instead of Last/First).
Correct me if i am wrong. Cheers.

--- markus
 
I've run a simple 'SELECT * FROM Table1' command and done a RecordCount against the TQuery and it gives me the required answer.
I had no need for First or Last calls - although maybe that is the safer way of doing things with this ?

If I'm doing things wrong then it's wiser I start to do them right ....

Steve
 
I have the same experience with RecordCount as Steve. Steven van Els
SAvanEls@cq-link.sr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top