<?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>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sun, 21 Mar 2010 01:49:34 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<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>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>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>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>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>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>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>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>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>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>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>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>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>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>&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>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>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>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>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>
