Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 exec not working

Author  Topic 

Starting Member

6 Posts

Posted - 2005-08-26 : 12:00:24
DECLARE @sql nchar(100)

set @sql = 'SELECT * INTO #bolo FROM ['+@lcTableListBeforeLast+']'

exec sp_executesql @sql

Master Smack Fu Yak Hacker

2916 Posts

Posted - 2005-08-26 : 12:12:09
temp table (#) gone out of scope after the end of the EXEC...a ## temp table may live up on TEMP table + SCOPE
Go to Top of Page

Starting Member

6 Posts

Posted - 2005-08-26 : 12:25:55
thx Andrew, you got right, i used ## tables and not it works cool
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-08-26 : 14:28:20
It is better to use a #temp table. Global temp tables can cause problems if the same stored procedure can be run more than once at the same time, or if some other stored proc uses the same global temp table name. Also, SELECT INTO can cause a schema lock on the tempdb database until the query completes, and cause concurrency issues.

You can do this by running a create table statement before your EXECUTE:

create #bolo
col1 int not null,
col1 int not null

set @sql =
'INSERT INTO #bolo (col1,col2) '+

Go to Top of Page

- Advertisement -