有个触发器在更新表的时候执行
update 原料 set 单价=总价/库存数现在我发现当遇到库存数减为0了会出错,应该如何修改触发器令库存数为0时单价也为0就可以。

解决方案 »

  1.   


    update 原料 set 单价=总价/nullif(库存数,0)
      

  2.   


    --或者
    update 原料 set 单价=case when 库存数=0 then 0 else 总价/库存数 end
      

  3.   

    update 原料 set 单价=case when 库存数=0 then 0 else 总价/库存数 end
      

  4.   


    update 原料 
    set 单价=case when 库存数<>0 then 总价/库存数 else 0 end
      

  5.   

    update 原料 set 单价=case when 库存数=0 then 0 else 总价/库存数 end
      

  6.   

    update 原料 set 单价=case 库存数 when 0 then 0 else 总价/库存数 end
      

  7.   

    update 原料 set 单价=(case when isnull(库存数,0)=0 then 0 else 总价/库存数 end)
      

  8.   

    update 原料 set 单价=总价/nullif(库存数,0)