Please start any new threads on our new site at https://forums.sqlteam.com. 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 

lukit
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

AndrewMurphy
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 longer....read up on TEMP table + SCOPE
Go to Top of Page

lukit
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) '+
'SELECT * FROM ['+
@lcTableListBeforeLast+']'



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -