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
 General SQL Server Forums
 New to SQL Server Programming
 how to delele temprapyy file

Author  Topic 

jeff06
Posting Yak Master

166 Posts

Posted - 2007-05-21 : 08:21:51
for table #t
Can someone provide code to do following task? Thanks

if #t exists,
drop table #t

Thanks.

Jeff

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-21 : 08:24:08
[code]
if object_id('tempdb..#t') is not null
drop table #t
[/code]


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

jeff06
Posting Yak Master

166 Posts

Posted - 2007-05-21 : 08:45:26
THX
Go to Top of Page

jeff06
Posting Yak Master

166 Posts

Posted - 2007-05-21 : 09:00:12
if object_id('tempdb.dbo. #allnew104_506') is not null
drop table #allnew104_506

select *,1 as forlogistic into #allnew104_506
from rpt_contractdetails
where creationdate>='5/1/2004' and fundedamount>0
and creationdate<'6/1/2006' and contracttypename='New'


When I run above code i got error msg:
Server: Msg 2714, Level 16, State 6, Line 4
There is already an object named '#allnew104_506' in the database.

It seems the table #allnew104_506 has not been deleted before it is re created.
How can I fix this problem?
Thanks
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-05-21 : 09:47:27
Well, yeah.

Stop shooting yourself in the foot.

The temp table can only exist in the spid that it got created, so you should know if it exists, because you created it previously.

There should be no need to drop a temp table before it's creation

It is a good idea to drop it on the completeion of the thread however, even if it does get droped at the end of scope



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -