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 2005 Forums
 Transact-SQL (2005)
 Create temp table name with string variable

Author  Topic 

brianpark
Starting Member

6 Posts

Posted - 2007-03-29 : 10:09:34
Hi,
I need to create a temptable with name string variable passed from user. I am going to use a timestamp as part of name table.
I planned build @StrName = "#Temp" + dateTime and pass it to the Stored Procedure to create temp table using

Create Table @StrName
(
SpecCD int,
SpecID varchar()
)

I think I can't use string variable as a temp table name.
Is it possible to creat a local temp table with dynamically generated string as a table name?

Thanks in advance.
Brian.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-29 : 10:13:43
Is it possible to creat a local temp table with dynamically generated string as a table name?

It is possible but all subsequent operations on that temp table will have to be written as D-SQL only like:

Exec('create table #temp1(a int); insert #temp1 values(1); select * from #temp1')


Anyway, what is the purpose of creating local temp table with dynamic name?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-29 : 11:14:51
Why do you want to create a temp table with timestamp as part of the name ?

Do you know that local temp table exists only to the connection ? You can have 100 connections to the SQLServer creating temp table with the same name.


KH

Go to Top of Page
   

- Advertisement -