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 2008 Forums
 Transact-SQL (2008)
 using GUID as temp table name

Author  Topic 

pithhelmet
Posting Yak Master

183 Posts

Posted - 2011-09-09 : 13:53:57
Hi everyone,

I would like to start using a new guid for my temp tables.

I am trying something like this....

DECLARE @table1 sysname
SET @table1 = '#'+REPLACE(NEWID(),'-','')
SELECT * INTO '+@table1+' FROM [dbo].[Client_Type]

but i am failing with the select into line....

any ideas?

thanks
tony

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-09-09 : 13:59:01
Why does the table name have to be dynamic? You'll need dynamic SQL for that, which is really not advised.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-09 : 15:13:28
Just to check: Do you know that two people can do

SELECT ... INTO #MyTempTable ...

at the same time and there is no problem with the fact that both users have identical "#MyTempTable" names ?
Go to Top of Page
   

- Advertisement -