SQL Server Temp Tables across multiple scripts/tabs
I read a quote from Zed Shaw once that said something like "if a software developer writes the same code more than once, he should write a function so he doesn't have to repeat himself".
On a daily basis, I find myself making temp tables in SQL Server more than once per day. I don't need these tables to live past midnight each day which is why I chose to use a temp table. However, I have various scripts in different tabs in SQL Management Studio - I have to repeat these temp tables in every one of the scripts in order to reference it, and this seems quite inefficient. My ultimate goal would be to run a stored procedure that would populate multiple temp tables and have them available to run my analyses.
Is there a better way to reference the tables than my current usage? Is there a way to reference the temp tables across all sessions in SQL Server 2008?
It seems that what you want are global temporary tables. The syntax to use them is the same as normal temporary tables, but they have two ## instead of one (##temptable). Please take a look at the link first to know the limitations of them.