update 库存 a set 库存数量=(case when a.库存数量-b.计划数量>=0 then a.库存数量-b.计划数量 else 0 end),库存金额=( case when a.库存金额-b.计划金额>=0 then a.库存金额-b.计划金额 else 0 end) from 计划 b where a.物品名称=b.物品名称

解决方案 »

  1.   

    update 库存 set 库存数量=case when 库存数量-a.计划数量>=0 then 库存数量-a.计划数量 else 0 end,库存金额=case when 库存金额-a.计划金额>=0 then 库存金额-a.计划金额 else 0 end
    from 计划 a where 库存.物品名称=a.物品名称 and 库存.类别=a.类别
      

  2.   

    update 库存 
    set 
    库存数量=case when 库存数量-a.计划数量>=0 then 库存数量-a.计划数量 else 0 end,
    库存金额=case when 库存金额-a.计划金额>=0 then 库存金额-a.计划金额 else 0 end
    from 计划 a, 库存 b
    where b.物品名称=a.物品名称 and b.类别=a.类别
      

  3.   

    or 
    update a set a.库存数量=case when a.库存数量-b.计划数量>=0 then a.库存数量-b.计划数量 else 0 end,a.库存金额=case when a.库存金额-b.计划金额>=0 then a.库存金额-b.计划金额 else 0 end
    from 库存a, 计划 b where a.物品名称=b.物品名称 and a.类别=b.类别
      

  4.   

    update 库存 set 库存数量=case when 库存.库存数量-计划.计划数量>0 then 库存.库存数量-计划.计划数量 else 0 end
    , 库存金额=case when 库存.库存金额-计划.计划金额>0 then 库存.库存金额-计划.计划金额 else 0 end
    from 计划 where 库存.物品名称=计划.物品名称 and 库存.类别=计划.类别
      

  5.   

    update 库存 set 库存数量=case when 库存.库存数量-计划.计划数量>0 then 库存.库存数量-计划.计划数量 else 0 end,库存金额=case when 库存.库存金额-计划.计划金额>0 then 库存.库存金额-计划.计划金额 else 0 end from 计划 where 库存.物品名称=计划.物品名称 and 库存.类别=计划.类别
      

  6.   

    update 库存 set 库存数量=case when 库存.库存数量-计划.计划数量>0 then 库存.库存数量-计划.计划数量 else 0 end
    , 库存金额=case when 库存.库存金额-计划.计划金额>0 then 库存.库存金额-计划.计划金额 else 0 end
    from 计划 where 库存.物品名称=计划.物品名称 and 库存.类别=计划.类别
      

  7.   

    update 库存 set 库存数量=case when 库存.库存数量-计划.计划数量>=0 then 库存.库存数量-计划.计划数量 else 0 end
    , 库存金额=case when 库存.库存金额-计划.计划金额>=0 then 库存.库存金额-计划.计划金额 else 0 end
    from 计划 where 库存.物品名称=计划.物品名称 and 库存.类别=计划.类别