BUG: Docerr: Nested Stored Procedure and Temporary ObjectsLast reviewed: April 28, 1997Article ID: Q101666 |
The information in this article applies to:
SYMPTOMSOn page 292 of Transact-SQL "User's Guide," it is incorrectly stated that:
If you execute a procedure that calls another procedure, the called procedure can access all objects except temporary tables created by the first procedure.However, the called procedure can access the temporary tables created by the parent procedure. Therefore, the correct statement should be:
If you execute a procedure that calls another procedure, the called procedure can access all objects created by the first procedure.However, there is one exception to this case. When the called procedure contains a conditional CREATE TABLE statement for the same temporary table name, then the called procedure fails to find the temporary object created by calling procedure.
ExampleFor example, consider the following where proca is the calling procedure and procb is the called procedure:
create proc proca as create table #t1 (i int) execute procb go create table #t1 (i int) go create proc procb as if not exists (select name from tempdb..sysobjects where substring(name,1,3)='#t1') create table #t1 (i int) select * from #t1 go drop table #t1 go execute proca goIn this case, the execution of procedure proca fails indicating that the object #t1 cannot be found. However, if there is no CREATE statement in the IF EXIST clause, then the above script executes without any errors.
|
Additional query words:
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |