Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Record Count

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-12-12 : 07:26:36
Ricardo writes "I have a application in C++ with OLE DB which I have to know in advance how many records will be returned in my query. So I query two selects:
"select count( RecordId ) from Table where Column = 1"
"select Name, Job from Table where Column = 1"

But that way I have to scan the table for the same records twice, which is pretty much slower. Is there any way I can improve it?

I though about using select @@RowCount but it's not possible, since I would have to move between result sets.

Thx,
Ricardo"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-12 : 07:44:24
Instead of count(RecordId) use Count(*) so that optimiser will make use of index if any

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-12-12 : 14:27:51
Or possibly:

SET NOCOUNT ON

select Name, Job
INTO #MyTempTable
from Table where Column = 1

SELECT @@ROWCOUNT AS [MyCount]

select Name, Job
FROM #MyTempTable


SET NOCOUNT OFF

Kristen
Go to Top of Page
   

- Advertisement -