如何在此case语句中处理零除

时间:2019-01-22 17:15:26

标签: sql division handle zero

在这种情况下,我有一个“除以”。如何修改此值以通过零错误处理div?

CASE WHEN INVOICE_V.INVC_TYPE = 0 then 
    (((INVC_ITEM_V.PRICE - INVC_ITEM_V.TAX_AMT)*INVC_ITEM_V.QTY) -  
     (INVC_ITEM_V.COST * INVC_ITEM_V.QTY)) 
        / ((INVC_ITEM_V.PRICE - INVC_ITEM_V.TAX_AMT)*INVC_ITEM_V.QTY)*100 
    else 0 END as EXT_M_PERCENT,

1 个答案:

答案 0 :(得分:1)

如果用“句柄”表示返回0,则可以这样做:

CASE WHEN INVOICE_V.INVC_TYPE = 0 
      AND (((INVC_ITEM_V.PRICE - INVC_ITEM_V.TAX_AMT)*INVC_ITEM_V.QTY) <> 0 THEN