use tempdb  select name from sysobjects where name like '#cgwfbb%'
我是这样查的。所以是模糊查询,怎样完全查找。name                                                                                                                             
-------------------------------------------------------------------------------------------------------------------------------- 
#cgwfbb_____________________________________________________________________________________________________________00000000000B(1 row(s) affected)

解决方案 »

  1.   

    if exists(select name from tempdb..sysobjects where name Like ('#cgwfbb%')) drop table #cgwfbb;
    select name from tempdb..sysobjectsServer: Msg 3701, Level 11, State 5, Line -2118799728
    Cannot drop the table '#cgwfbb', because it does not exist in the system catalog.
    name
      

  2.   

    if object_id('#table1') is not null 
      drop table #table1
      

  3.   

    不用这么麻烦!
    只要是同一个连接,
    if exists(select name from tempdb..sysobjects where name ='#cgwfbb' )
    drop table #cgwfbb;
      

  4.   

    这样不行的。 如果其它用户也在操作该模块, 当然是不同连接,
    if exists(select name from tempdb..sysobjects where name ='#cgwfbb' )
    执行这个反回结果为True. 还是不行。 
    我后来是这样解决这个问题的。if exists (select * from tempdb..sysobjects where id=object_id('tempdb..#cgwfbb')) drop table #cgwfbb;
    执行结果正确, 但我不太明白id=object_id这个函数的用途
      

  5.   

    因为每个用户创建的临时表名 即使是同一个模块,创建的表名都不相同,所以要查找创建的本地临时好像就只能通过,我昨天试了好多。 不知还有其它的方法没有。if exists (select * from tempdb..sysobjects where id=object_id('tempdb..#cgwfbb')) drop table #cgwfbb;