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)
 Live of temporary table

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-09-17 : 14:04:14
I used a store procedure sp1 to create a temporary table #OrderAll.
And then, used another store procedure sp2 to

select * from #OrderAll where order_date >= '01/01/2008'

I got an error said:

invalid object #OrderAll

What is live of temporary table?

How can I select data from a temporary table which was created in another store procedure?

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-09-17 : 14:10:58
Sorry, the title should be "The life of temporary table"
Go to Top of Page

YellowBug
Aged Yak Warrior

616 Posts

Posted - 2009-09-17 : 14:42:30
Temp tables are dropped when batch in which they are created goes out of scope.

Here's a nice write-up:
http://www.nigelrivett.net/SQLTsql/AccessTempTablesAcrossSPs.html
Go to Top of Page

sanoj_av
Posting Yak Master

118 Posts

Posted - 2009-09-18 : 00:49:10
Create a global Temporary table with ## as follows
Create Table ##OrderAll..
But here too, the life of the temp table is only upto the end of the session that created the table. It would work if you call both of your procs in the same session.
Go to Top of Page
   

- Advertisement -