IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE   id =object_id('tempdb.dbo#temp)) 
    DROP TABLE tempdb.#tempcreate table #temp(...)select * into #temp from .....我在存储过程中这样写。
执行的时候 这句报#tempe对象已经存在。请假解决方法

解决方案 »

  1.   

    create table #temp(...)insert into #temp select *  from ..... 
      

  2.   

    不存在 用 select...into...
    存在用insert into #temp select *  from ..... 
      

  3.   

    select * into 表
    是会创建表的,请应用insert into 表 select * from ...
      

  4.   

    create table #temp(...) insert into  #temp select * from .....
      

  5.   


    IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE  id =object_id('tempdb.dbo#temp)) 
        DROP TABLE tempdb.#temp create table #temp(...) insert into #temp 
    select * from ..... 
      

  6.   

    create table 

    select * into ...都会创建表,出现重复错误的提示是肯定的
      

  7.   

    create table #temp(...) select * into #temp from ..... 
    这两句都是创建表
      

  8.   

    貌似和楼上一位的意见一样,不过还是写写吧
    用这个判断是否存在,
    select * from tempdb.sys.objects where object_id = object_id('tempdb..#tempTable1')
    如果存在
    drop table #tempTable1
      

  9.   


    select * into #temp from .....这句是在临时表不存在时才可以select
    因为你已创建临时表 create table #temp(...)
    方案一:select * into #temp from .....可改为insert into #temp select * from ...
    方案二:删掉create table #temp(...)
      

  10.   

    楼主要是想判断临时表是否存在,可以这样做--判断临时表是否存在
    --测试通过
    --临时表存在则先删除
    if object_id('tempdb..#temp','U') is not null
    drop table #temp;
    --创建临时表
    create table #temp
    (
     test char(2)
    )