<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; How to Drop Temp Table &#8211; Check Existence of Temp Table</title>
	<atom:link href="http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 10 Feb 2012 02:12:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Jason</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-231788</link>
		<dc:creator><![CDATA[Jason]]></dc:creator>
		<pubDate>Thu, 05 Jan 2012 10:43:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-231788</guid>
		<description><![CDATA[if OBJECT_ID(‘tempdb..#temp’)&gt;0 DROP TABLE #temp
This will not work on SQL Server 2012, as OBJECT_ID for temp tables will return negative values]]></description>
		<content:encoded><![CDATA[<p>if OBJECT_ID(‘tempdb..#temp’)&gt;0 DROP TABLE #temp<br />
This will not work on SQL Server 2012, as OBJECT_ID for temp tables will return negative values</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: I love SQL</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-223941</link>
		<dc:creator><![CDATA[I love SQL]]></dc:creator>
		<pubDate>Thu, 22 Dec 2011 20:23:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-223941</guid>
		<description><![CDATA[shorter of all
if OBJECT_ID(&#039;tempdb..#temp&#039;)&gt;0 DROP TABLE #temp]]></description>
		<content:encoded><![CDATA[<p>shorter of all<br />
if OBJECT_ID(&#8216;tempdb..#temp&#8217;)&gt;0 DROP TABLE #temp</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mrityunjay Singh</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-168016</link>
		<dc:creator><![CDATA[Mrityunjay Singh]]></dc:creator>
		<pubDate>Wed, 14 Sep 2011 12:27:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-168016</guid>
		<description><![CDATA[sivaramakrishnan

Sorry i am late, But if you code same type or error again then please use this code to solve your error

            SELECT @MYQUERY = &#039;IF EXISTS ( SELECT * FROM TEMPDB..SYSOBJECTS WHERE NAME LIKE &#039;&#039;%##PF&#039; + CAST ( @@SPID AS VARCHAR ) + &#039;%&#039;&#039; ) DROP TABLE ##PF&#039; + CAST ( @@SPID AS VARCHAR )  
			EXECUTE ( @MYQUERY )]]></description>
		<content:encoded><![CDATA[<p>sivaramakrishnan</p>
<p>Sorry i am late, But if you code same type or error again then please use this code to solve your error</p>
<p>            SELECT @MYQUERY = &#8216;IF EXISTS ( SELECT * FROM TEMPDB..SYSOBJECTS WHERE NAME LIKE &#8221;%##PF&#8217; + CAST ( @@SPID AS VARCHAR ) + &#8216;%&#8221; ) DROP TABLE ##PF&#8217; + CAST ( @@SPID AS VARCHAR )<br />
			EXECUTE ( @MYQUERY )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mrityunjay Singh</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-168015</link>
		<dc:creator><![CDATA[Mrityunjay Singh]]></dc:creator>
		<pubDate>Wed, 14 Sep 2011 12:24:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-168015</guid>
		<description><![CDATA[sivaramakrishnan,

please use this to solve your error

SELECT @MYQUERY = &#039;IF EXISTS ( SELECT * FROM TEMPDB..SYSOBJECTS WHERE NAME LIKE &#039;&#039;%##PF&#039; + CAST ( @@SPID AS VARCHAR ) + &#039;%&#039;&#039; ) DROP TABLE ##PF&#039; + CAST ( @@SPID AS VARCHAR )  
EXECUTE ( @MYQUERY )]]></description>
		<content:encoded><![CDATA[<p>sivaramakrishnan,</p>
<p>please use this to solve your error</p>
<p>SELECT @MYQUERY = &#8216;IF EXISTS ( SELECT * FROM TEMPDB..SYSOBJECTS WHERE NAME LIKE &#8221;%##PF&#8217; + CAST ( @@SPID AS VARCHAR ) + &#8216;%&#8221; ) DROP TABLE ##PF&#8217; + CAST ( @@SPID AS VARCHAR )<br />
EXECUTE ( @MYQUERY )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sivaramakrishnan</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-162612</link>
		<dc:creator><![CDATA[sivaramakrishnan]]></dc:creator>
		<pubDate>Sat, 27 Aug 2011 12:03:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-162612</guid>
		<description><![CDATA[how to delete ##teemp table please clarify this...]]></description>
		<content:encoded><![CDATA[<p>how to delete ##teemp table please clarify this&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sara</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-132504</link>
		<dc:creator><![CDATA[Sara]]></dc:creator>
		<pubDate>Mon, 02 May 2011 11:39:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-132504</guid>
		<description><![CDATA[Useful &amp; to the point .Keep it up]]></description>
		<content:encoded><![CDATA[<p>Useful &amp; to the point .Keep it up</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raghuveer</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-101681</link>
		<dc:creator><![CDATA[Raghuveer]]></dc:creator>
		<pubDate>Tue, 23 Nov 2010 13:57:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-101681</guid>
		<description><![CDATA[Hi is it good to write many stored procedure and call one with in one instead of writing one single 6 to 15 pages stored procedure.
 I am assuming that sp execute like parallel programming.]]></description>
		<content:encoded><![CDATA[<p>Hi is it good to write many stored procedure and call one with in one instead of writing one single 6 to 15 pages stored procedure.<br />
 I am assuming that sp execute like parallel programming.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rinku</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-87816</link>
		<dc:creator><![CDATA[Rinku]]></dc:creator>
		<pubDate>Tue, 14 Sep 2010 12:25:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-87816</guid>
		<description><![CDATA[Nice Article! as OBJECT_ID() function returns details related to temp table in context of current session so won&#039;t get multiple entries for tables starting with same name, as system suffixes some numbers after local temp table. so it will be tough to identify row related to session in context.]]></description>
		<content:encoded><![CDATA[<p>Nice Article! as OBJECT_ID() function returns details related to temp table in context of current session so won&#8217;t get multiple entries for tables starting with same name, as system suffixes some numbers after local temp table. so it will be tough to identify row related to session in context.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Hiren Solanki</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-85328</link>
		<dc:creator><![CDATA[Hiren Solanki]]></dc:creator>
		<pubDate>Thu, 26 Aug 2010 10:14:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-85328</guid>
		<description><![CDATA[Hi Pinal,
Nice Article.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
Nice Article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: deepak Kumar</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-83816</link>
		<dc:creator><![CDATA[deepak Kumar]]></dc:creator>
		<pubDate>Thu, 12 Aug 2010 09:14:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-83816</guid>
		<description><![CDATA[IF OBJECT_ID(&#039;tempdb..#TEMP&#039;) IS NOT NULL
BEGIN 
     DROP TABLE #TEMP
END]]></description>
		<content:encoded><![CDATA[<p>IF OBJECT_ID(&#8216;tempdb..#TEMP&#8217;) IS NOT NULL<br />
BEGIN<br />
     DROP TABLE #TEMP<br />
END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Saby</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-71446</link>
		<dc:creator><![CDATA[Saby]]></dc:creator>
		<pubDate>Tue, 18 May 2010 17:31:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-71446</guid>
		<description><![CDATA[Here i really like to make a comment that i m getting an issue with the tempdb as there are some blocking seen while there is a temp table created wthin the procedures there.

Eg there is a procedure wthin the procedure the are nested procedure called.]]></description>
		<content:encoded><![CDATA[<p>Here i really like to make a comment that i m getting an issue with the tempdb as there are some blocking seen while there is a temp table created wthin the procedures there.</p>
<p>Eg there is a procedure wthin the procedure the are nested procedure called.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Paul</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-63756</link>
		<dc:creator><![CDATA[Paul]]></dc:creator>
		<pubDate>Thu, 25 Mar 2010 16:08:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-63756</guid>
		<description><![CDATA[Thanks, this worked for me as well. I had been going nuts trying to figure this out.

IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE ID = OBJECT_ID(N&#039;tempdb..#t&#039;)) BEGIN DROP TABLE #t END]]></description>
		<content:encoded><![CDATA[<p>Thanks, this worked for me as well. I had been going nuts trying to figure this out.</p>
<p>IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE ID = OBJECT_ID(N&#8217;tempdb..#t&#8217;)) BEGIN DROP TABLE #t END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SRPBHUSHAN</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-62895</link>
		<dc:creator><![CDATA[SRPBHUSHAN]]></dc:creator>
		<pubDate>Sun, 14 Mar 2010 06:02:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-62895</guid>
		<description><![CDATA[Here is the Example.
I have two tables Manager and Employee each has different Empids and Salaries so i want to get the Maximum sal of the Two tables.for that i have used #temptables.

select salary into #temptbks from Empsal Union select salary from Managers;select max(salary)as salary from #temptbks;
drop table #temptbks.As soon as temptable is created U should delete so that u can use that same table if the Original table has been Updated.The #temptable will be available in that database itself.In sql-server.If u want this query in asp.net than go for Stored procedure.]]></description>
		<content:encoded><![CDATA[<p>Here is the Example.<br />
I have two tables Manager and Employee each has different Empids and Salaries so i want to get the Maximum sal of the Two tables.for that i have used #temptables.</p>
<p>select salary into #temptbks from Empsal Union select salary from Managers;select max(salary)as salary from #temptbks;<br />
drop table #temptbks.As soon as temptable is created U should delete so that u can use that same table if the Original table has been Updated.The #temptable will be available in that database itself.In sql-server.If u want this query in asp.net than go for Stored procedure.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-62668</link>
		<dc:creator><![CDATA[Pinal Dave]]></dc:creator>
		<pubDate>Wed, 10 Mar 2010 17:30:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-62668</guid>
		<description><![CDATA[Hi Mike,

The objectid of temporary table can be viewed by this query:

select OBJECT_ID(&#039;tempdb.dbo.#tmp_mwj&#039;)

Regards,
Pinal Dave]]></description>
		<content:encoded><![CDATA[<p>Hi Mike,</p>
<p>The objectid of temporary table can be viewed by this query:</p>
<p>select OBJECT_ID(&#8216;tempdb.dbo.#tmp_mwj&#8217;)</p>
<p>Regards,<br />
Pinal Dave</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mike</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-62648</link>
		<dc:creator><![CDATA[mike]]></dc:creator>
		<pubDate>Wed, 10 Mar 2010 13:00:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-62648</guid>
		<description><![CDATA[Well when I try this I get a NULL value returned.

select my_id, my_name
into #tmp_mwj
from dbo.my_table

(creates table)


select OBJECT_ID(&#039;dbo.#tmp_mwj&#039;)
(returns null)

SELECT 1
FROM dbo.sysobjects
WHERE ID = OBJECT_ID(&#039;dbo.#tmp_mwj&#039;)]]></description>
		<content:encoded><![CDATA[<p>Well when I try this I get a NULL value returned.</p>
<p>select my_id, my_name<br />
into #tmp_mwj<br />
from dbo.my_table</p>
<p>(creates table)</p>
<p>select OBJECT_ID(&#8216;dbo.#tmp_mwj&#8217;)<br />
(returns null)</p>
<p>SELECT 1<br />
FROM dbo.sysobjects<br />
WHERE ID = OBJECT_ID(&#8216;dbo.#tmp_mwj&#8217;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: medamo</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-61447</link>
		<dc:creator><![CDATA[medamo]]></dc:creator>
		<pubDate>Thu, 18 Feb 2010 18:03:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-61447</guid>
		<description><![CDATA[Thanks! This was a great place to get a working solution for us.  I modified it slightly:
Select 
	1 
FROM 
	tempdb.dbo.sysobjects (nolock) 
WHERE 
	ID = OBJECT_ID(N&#039;tempdb.dbo.#batch&#039;) and 
	[Type] = &#039;U&#039;

Our deployment team doesn&#039;t like &quot;Select *&quot; for any reason, also added a (nolock) hint and limited it User &#039;U&#039; object types only.]]></description>
		<content:encoded><![CDATA[<p>Thanks! This was a great place to get a working solution for us.  I modified it slightly:<br />
Select<br />
	1<br />
FROM<br />
	tempdb.dbo.sysobjects (nolock)<br />
WHERE<br />
	ID = OBJECT_ID(N&#8217;tempdb.dbo.#batch&#8217;) and<br />
	[Type] = &#8216;U&#8217;</p>
<p>Our deployment team doesn&#8217;t like &#8220;Select *&#8221; for any reason, also added a (nolock) hint and limited it User &#8216;U&#8217; object types only.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Umesh</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-59827</link>
		<dc:creator><![CDATA[Umesh]]></dc:creator>
		<pubDate>Sat, 16 Jan 2010 06:49:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-59827</guid>
		<description><![CDATA[Thank You sir]]></description>
		<content:encoded><![CDATA[<p>Thank You sir</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wael</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-58134</link>
		<dc:creator><![CDATA[wael]]></dc:creator>
		<pubDate>Thu, 03 Dec 2009 07:11:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-58134</guid>
		<description><![CDATA[Thank You Very Much 
it work perfectly with me]]></description>
		<content:encoded><![CDATA[<p>Thank You Very Much<br />
it work perfectly with me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe Chapman</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-57698</link>
		<dc:creator><![CDATA[Joe Chapman]]></dc:creator>
		<pubDate>Wed, 18 Nov 2009 13:29:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-57698</guid>
		<description><![CDATA[&quot;i tired using it
i get sysntax error
Incorrect syntax near ‘)’ &quot; - SVK

I suspect that this is because the character ’ (single quote) is invalid, it should be &#039; (apostrophe) instead.

What I suspect has happened is that either the database for this website is converting apostrophes to single quote or the developer of the query pasted their query into MS Word which then assumed that the character should be a single quote and converted it.

Solution: Try replacing all single quote characters to apostrophes. I did that and it works fine for me.]]></description>
		<content:encoded><![CDATA[<p>&#8220;i tired using it<br />
i get sysntax error<br />
Incorrect syntax near ‘)’ &#8221; &#8211; SVK</p>
<p>I suspect that this is because the character ’ (single quote) is invalid, it should be &#8216; (apostrophe) instead.</p>
<p>What I suspect has happened is that either the database for this website is converting apostrophes to single quote or the developer of the query pasted their query into MS Word which then assumed that the character should be a single quote and converted it.</p>
<p>Solution: Try replacing all single quote characters to apostrophes. I did that and it works fine for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SVK</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-57523</link>
		<dc:creator><![CDATA[SVK]]></dc:creator>
		<pubDate>Wed, 11 Nov 2009 12:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-57523</guid>
		<description><![CDATA[i tired using it 
i get sysntax error 
Incorrect syntax near &#039;)&#039;]]></description>
		<content:encoded><![CDATA[<p>i tired using it<br />
i get sysntax error<br />
Incorrect syntax near &#8216;)&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron Sanek</title>
		<link>http://blog.sqlauthority.com/2009/05/17/sql-server-how-to-drop-temp-table-check-existence-of-temp-table/#comment-54284</link>
		<dc:creator><![CDATA[Aaron Sanek]]></dc:creator>
		<pubDate>Thu, 30 Jul 2009 20:58:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=4936#comment-54284</guid>
		<description><![CDATA[Below is how you can check and delete temp tables.

IF EXISTS
(
	SELECT *
	FROM tempdb.dbo.sysobjects
	WHERE ID = OBJECT_ID(N&#039;tempdb..#MyTempTable&#039;)
)
BEGIN
	DROP TABLE #MyTempTable
END]]></description>
		<content:encoded><![CDATA[<p>Below is how you can check and delete temp tables.</p>
<p>IF EXISTS<br />
(<br />
	SELECT *<br />
	FROM tempdb.dbo.sysobjects<br />
	WHERE ID = OBJECT_ID(N&#8217;tempdb..#MyTempTable&#8217;)<br />
)<br />
BEGIN<br />
	DROP TABLE #MyTempTable<br />
END</p>
]]></content:encoded>
	</item>
</channel>
</rss>

