PRB: Process All Results to Find Number of Rows Affected

Last reviewed: April 25, 1997
Article ID: Q70673

kbprg The information in this article applies to:

  • Microsoft SQL Server Programmer's Toolkit, version 4.2

SYMPTOMS

In a DB-Library (DB-Lib) application that performs SELECT statements that return large numbers of result rows, the following procedure is being used to find out how many rows are returned without processing the entire query.

If a SELECT statement is performed by calling the DBSQLEXEC() and DBRESULTS() functions, and then calling the DBCANCEL() function to cancel the query without processing the rows, a subsequent call to the DBCOUNT() function returns an incorrect number of rows.

CAUSE

This functionality is not supported by the Microsoft SQL Server and DB-Library.

WORKAROUND

In the case above, the number of rows returned by DBCOUNT() is the number of rows that were sent to the workstation before the query was canceled. This also occurs in SAF when the F6 key, which aborts processing of the query, is pressed before the query completes. A subsequent "SELECT @@rowcount" shows the number of rows sent to the workstation before the query was aborted.

To find the number of rows that would be returned without looping through each row in a DB-Lib application, issue the command "SELECT COUNT(*)" with the same WHERE clause as the original SELECT statement. This command is faster than processing each row, because only one row is returned from the SQL Server.


Additional query words: dblib Windows NT
Keywords : kbprg SSrvDB_Lib SSrvProg SSrvWinNT
Version : 4.2 | 4.2 | 4.2
Platform : MS-DOS OS/2 WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 25, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.