BUG: Errors 2714 and 267 on INSERT INTO Global Temp TableLast reviewed: April 16, 1997Article ID: Q166200 |
The information in this article applies to:
SYMPTOMSAn INSERT INTO a global temp table from a stored procedure may result in the following errors during the second and third executions:
At the second execution: Msg 2714, Level 16, State 1 There is already an object named '%.*s' in the database. At the third execution: Msg 267, Level 16, State 1 Object '%.*s' cannot be found.The following script demonstrates the problem:
DROP PROCEDURE sp_test GO CREATE PROCEDURE sp_test AS EXEC ("IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE name = '##testTable' AND type = 'u') DROP TABLE ##testTable") CREATE TABLE ##testTable (col INT) INSERT INTO ##testTable SELECT 1 cleanup: EXEC ("IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE name = '##testTable' AND type = 'u') DROP TABLE ##testTable") GO EXEC sp_test /* First execution */ This command did not return data, and it did not return any rows. EXEC sp_test /* Second execution */ Msg 2714, Level 16, State 1 There is already an object named '##testTable' in the database. EXEC sp_test /* Third execution */ Msg 267, Level 16, State 1 Object '' cannot be found. WORKAROUNDTo work around this problem, do either of the following:
CREATE PROCEDURE sp_test WITH RECOMPILE AS EXEC ("IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE name = '##testTable' AND type = 'u') DROP TABLE ##testTable") CREATE TABLE ##testTable (col INT) EXEC ('INSERT INTO ##testTable SELECT 1') cleanup: EXEC ("IF EXISTS (SELECT * FROM tempdb..sysobjects WHERE name = '##testTable' AND type = 'u') DROP TABLE ##testTable") GO STATUSMicrosoft has confirmed this to be a problem in Microsoft SQL Server version 6.5. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available. |
Keywords : kbbug6.50 kbusage SSrvStProc
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |