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 2012 Forums
 Transact-SQL (2012)
 Temp Table

Author  Topic 

SQLBoy14
Yak Posting Veteran

70 Posts

Posted - 2014-09-23 : 23:54:05
Hi sql expert,
if I have five different temp tables, is that other way to handle temp tables if I stop the query in between the execution? Below are basic sample of my temp tables:

SELECT A
INTO #TmpTbl1
FROM A table

SELECT A
INTO #TmpTbl1
FROM A table

SELECT B
INTO #TmpTbl2
FROM B table

SELECT C
INTO #TmpTbl3
FROM C table

SELECT D
INTO #TmpTbl4
FROM D table

SELECT *
FROM A Table
JOIN B Table
ON B = A
JOIN C Table
ON C = A
JOIN D Table
ON D = A

Drop table #TmpTbl1
Drop table #TmpTbl2
Drop table #TmpTbl3
Drop table #TmpTbl4

If I stop the execution in between, I have to highlight each Drop table #TmpTbl1 and #TmpTbl2 and #TmpTbl3 or #TmpTbl4 to re run the query. What is the better way to handle (create temp table) this so I don't have to execute each Drop Table #TmpTbl if I stop the query execution and re run it again?

Thank you all

SQLBoy

stepson
Aged Yak Warrior

545 Posts

Posted - 2014-09-24 : 00:58:48
[code]
IF OBJECT_ID('tempDB.dbo.#TmpTbl1') IS NULL
BEGIN
SELECT A
INTO #TmpTbl1
FROM A table
END
[/code]


sabinWeb MCP
Go to Top of Page
   

- Advertisement -