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.
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