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

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

lukit
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

AndrewMurphy
Flowing Fount of Yak Knowledge

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

lukit
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)

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



CODO ERGO SUM

Edited by - Michael Valentine Jones on 08/26/2005 14:28:59
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.27 seconds. Powered By: Snitz Forums 2000