INF: DECLARE CURSOR on Table Created in Stored Proc Fails

Last reviewed: May 1, 1997
Article ID: Q136821

The information in this article applies to:
  • Microsoft SQL Server, version 6.0

SUMMARY

If you create a table in a stored procedure and reference it in a DECLARE CURSOR statement, execution of the stored procedure will fail with:

   Msg 202, Level 11, State 2 "Internal error -- Unable to open
   table at query execution time."

MORE INFORMATION

- This problem occurs for either temporary or permanent tables.

- The error occurs if the table is created with either CREATE TABLE or

  SELECT INTO.

You can avoid this error message by either creating the table before you create the stored procedure, or enclosing the DECLARE CURSOR statement inside an EXEC statement, such as:

   EXEC("DECLARE hC CURSOR FOR select * from pubs")


Additional query words: sql6
Keywords : kbprg SSrvProg SSrvStProc
Version : 6.0
Platform : 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: May 1, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.