PRB: DECLARE CURSOR on Table Created in Stored Proc Fails

ID: Q136821


The information in this article applies to:


SYMPTOMS

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


WORKAROUND

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") 


MORE INFORMATION

This error occurs with either temporary or permanent tables in SQL Server version 6.0. With SQL Server 6.5, it only occurs with a permanent table. This error does not occur in SQL Server 7.0.

This error occurs if the table is created with either CREATE TABLE or SELECT INTO.

Additional query words: sql6


Keywords          : kbprg SSrvProg SSrvStProc 
Version           : winnt:6.0,6.5
Platform          : winnt 
Issue type        : kbprb 

Last Reviewed: March 9, 1999