SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Record Count
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 12/12/2005 :  07:26:36  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
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

India
22761 Posts

Posted - 12/12/2005 :  07:44:24  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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

United Kingdom
22415 Posts

Posted - 12/12/2005 :  14:27:51  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.25 seconds. Powered By: Snitz Forums 2000