declare @isWastage bit
declare @partcode varchar(20)set @isWastage=1
set @PartCode='1234567890'if @isWastage=1   --要求计算结果包含损耗
   select fpartcode, dosage INTO #TMP2 from tbom007d  where fparentpartcode = @PartCode
else 
   select fpartcode, dosage*2 INTO #TMP2 from tbom007d  where fparentpartcode = @PartCode                    --这一行出错出现以下错误:
服务器: 消息 2714,级别 16,状态 1,行 11
数据库中已存在名为 '#TMP2' 的对象。这是怎么回事啊?谢谢

解决方案 »

  1.   

    declare @isWastage bit
    declare @partcode varchar(20)set @isWastage=1
    set @PartCode='1234567890'if @isWastage=1   --要求计算结果包含损耗
       select fpartcode, dosage INTO #TMP1 from tbom007d  where fparentpartcode = @PartCode
    else 
       select fpartcode, dosage*2 INTO #TMP2 from tbom007d  where fparentpartcode = @PartCode
      

  2.   

    TO:caixia615(*^_^*)‵My ɡīr!.ˊ想念妳ˋ 。(*^_^*)  程序的目的是根据@isWastage是否为真,将不同的查询结果插入到一张新表#TMP2中.  当@isWastage为真时,不知道为什么也执行了else后边的语句
      

  3.   

    前面加个判断,如果存在#TMP2 就DROP吧
      

  4.   

    我在第一行加了一个 drop table #TMP2 结果也是一样的,加不加都一样
      

  5.   

    declare @isWastage bit
    declare @partcode varchar(20)set @isWastage=1
    set @PartCode='1234567890'if @isWastage=1   --要求计算结果包含损耗
       begin
       if object_id(N'Tempdb..#TMP2') is not null dorp table #tmp2
       select fpartcode, dosage INTO #TMP2 from tbom007d  where fparentpartcode = @PartCode
    end
    else 
    begin
       if object_id(N'Tempdb..#TMP2') is not null dorp table #tmp2   select fpartcode, dosage*2 INTO #TMP2 from tbom007d  where fparentpartcode = @PartCode 
    end                   --这一行出错
      

  6.   

    if @isWastage=1   
       insert into #tmp2 select fpartcode, dosage  from tbom007d  where fparentpartcode = @PartCode
    else 
       insert into #tmp2 select fpartcode, dosage*2  from tbom007d  where fparentpartcode = @PartCode
      

  7.   

    为什么有if条件判断,没有执行else后边的语句,程序还出错呢?