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.
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 anyMadhivananFailing to plan is Planning to fail |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-12-12 : 14:27:51
|
Or possibly:SET NOCOUNT ONselect Name, Job INTO #MyTempTablefrom Table where Column = 1SELECT @@ROWCOUNT AS [MyCount]select Name, Job FROM #MyTempTableSET NOCOUNT OFF Kristen |
|
|
|
|
|