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 2005 Forums
 Transact-SQL (2005)
 Create temp table name with string variable
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

6 Posts

Posted - 03/29/2007 :  10:09:34  Show Profile  Reply with Quote
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.

Flowing Fount of Yak Knowledge

5581 Posts

Posted - 03/29/2007 :  10:13:43  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
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
Go to Top of Page

In (Som, Ni, Yak)

17689 Posts

Posted - 03/29/2007 :  11:14:51  Show Profile  Reply with Quote
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.


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