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.
| Author |
Topic |
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-05-21 : 08:21:51
|
| for table #tCan someone provide code to do following task? Thanksif #t exists, drop table #tThanks.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 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-05-21 : 08:45:26
|
| THX |
 |
|
|
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_506select *,1 as forlogistic into #allnew104_506 from rpt_contractdetailswhere 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 4There 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 |
 |
|
|
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 creationIt is a good idea to drop it on the completeion of the thread however, even if it does get droped at the end of scopeBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
|
|
|