本帖最后由 800sun 于 2009-10-16 22:19:16 编辑

解决方案 »

  1.   

    if exists(....)
    ....
    esle
    ...
      

  2.   

    小F速度真快!!!请问,这个if exists(....)怎么构造?
      

  3.   

        if not exists(select 1 from invstock where batchno=? and wh_code=? and drug_id=? )
    begin 
        --如果库存无记录(这里应该怎么处理呢???)
        insert into invstock(wh_code,mid,totalnum)   
        select wh_code,mid,total
        from   invstock_in_detail
        where ..........
    end 
      

  4.   

    错了 drug_id 应该是mid
    反正就这个意思
      

  5.   


    if exists(select 1 from invstock a inner join invstock_in_detail b
        on  a.drug_id=b.drug_id
        where a.batchno=b.batchno and a.wh_code=@whcode and b.vouchno=@vcode)
    begin
    update...
    end
    else
    begin
    insert...
    end)
      

  6.   

    if exists(select 1 from invstock where ....)
    begin  
     --如果库存有记录
        update invstock set totalnum=totalnum+b.total
        from invstock a inner join invstock_in_detail b
        on  a.drug_id=b.drug_id
        where a.batchno=b.batchno and a.wh_code=@whcode and b.vouchno=@vcode
    end
    else
    begin    --如果库存无记录(这里应该怎么处理呢???)
        insert into invstock(wh_code,mid,totalnum)   
        select wh_code,mid,total
        from   invstock_in_detail
        where ..........
    end