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)
 variable temporary table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-03-02 : 07:55:55
adina writes "Hi, I made a stored procedure to create a temporary table (table name started with #). The passing variable for this procedure is 'table name'. The problem is the exec statement doesn't work, even though I get the right SQL statement.
This is the code:

create procedure test
@tablename varchar(50)
as
begin
set @tablename= '#'+@tablename
declare @sql varchar(8000)
set @sql= "create table " + @tablename + " (x int not null primary key, y int)"
print(@sql)
exec (@sql)
end

What should i do?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-03-02 : 07:58:28
Even if you got this to work, it is a TERRIBLE idea, and not particularly practical. I can't think of any reason why you'd need this, especially since the structure of the table doesn't change. Use a fixed name for the temp table instead.
Go to Top of Page
   

- Advertisement -