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
 Transact-SQL (2000)
 ##temp versus #temp

Author  Topic 

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-11 : 06:09:50
hi all.

this puzzles me:
this works:

DECLARE @strSql VARCHAR(50)
set @strSql = 'Select col1 into ##tempTable FROM MyTable'
EXEC(@strSql)
select * from ##tempTable

this doesn't:

DECLARE @strSql VARCHAR(50)
set @strSql = 'Select col1 into #tempTable FROM MyTable'
EXEC(@strSql)
select * from #tempTable

so why do ## work and # doesn't???

Go with the flow & have fun! Else fight the flow :)

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-11 : 06:17:51
never mind. i already found an answer...

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

real_pearl
Posting Yak Master

106 Posts

Posted - 2004-08-11 : 06:28:04
What answer you have found please tell me as well.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-11 : 06:32:57
i posted it in you topic :)
##temp is a global temporary table, while #temp is "local" temporary table (in one session).

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2004-08-11 : 07:18:39
Hello Spiritual person.

This doesn't work because when you execute a sql statement using exec('sql') the statement run in the exec is in it's own session.

This means that once that exec has completed that particular session has ended too.

The ##Temp tables as you said in another thread span across sessions - that's why they work in this case.


Duane.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-11 : 07:38:20
yeah i know :)) i found it in BOL under CREATE TABLE - go figure...

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -