Knowledge Base

PRB: DECLARE CURSOR on Table Created in Stored Proc Fails

Article ID: 136821

Article Last Modified on 10/30/2003


APPLIES TO


This article was previously published under Q136821

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 and SQL Server 2000.

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


Additional query words: sql6

Keywords: kbprogramming kbprb KB136821