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.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 exec not working
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

6 Posts

Posted - 08/26/2005 :  12:00:24  Show Profile  Reply with Quote
DECLARE @sql nchar(100)

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

exec sp_executesql @sql

Flowing Fount of Yak Knowledge

2916 Posts

Posted - 08/26/2005 :  12:12:09  Show Profile  Reply with Quote
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 - 08/26/2005 :  12:25:55  Show Profile  Reply with Quote
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 - 08/26/2005 :  14:28:20  Show Profile  Reply with Quote
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) '+


Edited by - Michael Valentine Jones on 08/26/2005 14:28:59
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.21 seconds. Powered By: Snitz Forums 2000