Fraser Kelly
Fraser Kelly

Reputation: 3

How can I handle a division by zero within this case statement

Within this case statement I have a "divide by". How can I modify this to handle div by zero errors?

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,

Upvotes: 0

Views: 77

Answers (1)

Hogan
Hogan

Reputation: 70523

If by "handle" you mean return 0, then you can do this:

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

Upvotes: 1

Related Questions