This is running on SQL Server 2008, but the database is in SQL Server 2000 compatibility mode (this I cannot change).
A temporary table is created at the beginning of the stored procedure and then insert into via an EXEC statement from dynamically generated SQL. How is this executing successfully, even though the temporary table (should be, from my understand) is out the execution scope, or does this get bypassed temporarily when performing these statements inside a stored procedure?
Example below:
CREATE PROCEDURE myProc (Param1 int....)
AS
BEGIN
Declare @SQL varchar(max) = null
Create table #tempTable
(
ID int,
Code1 varchar(255),
...
)
SET @SQL = 'insert into #tempTable '
+ ...
EXEC(@SQL)
Select * from #tempTable
END
Any help understanding this would be greatly appreciated!
Thanks!