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

brianpark
Starting Member

6 Posts

Posted - 03/29/2007 :  10:09:34  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
5509 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
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17601 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.


KH

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.06 seconds. Powered By: Snitz Forums 2000