none
Divide by zero error Message RRS feed

  • Question

  • Dear All,


    I'm getting the following error message Msg 8134, Level 16, State 1, Procedure "stored procedure name", Line 149
    Divide by zero error encountered, and I don't seem to find a way to fix the issue. I've looked at some Forums and one of them suggested that using
    SET ARITHABORT OFF
    GO
    SET ANSI_WARNINGS OFF
    GO
    Should resolve the problem, which it does but for some reason after I've altered the Stored Procedure to include it and reopen the SP, SET ARITHABORT OFF
    GO
    SET ANSI_WARNINGS OFF
    GO is no longer there. I'm not sure what I'm missing or are there other ways to resolve the error message?

    Thank you in advance!
    Thursday, April 11, 2013 9:28 AM

Answers

All replies

  • SELECT dividend / NULLIF(divisor, 0)
    Thursday, April 11, 2013 9:36 AM
  • Dear All,


    I'm getting the following error message Msg 8134, Level 16, State 1, Procedure "stored procedure name", Line 149
    Divide by zero error encountered, and I don't seem to find a way to fix the issue. I've looked at some Forums and one of them suggested that using
    SET ARITHABORT OFF
    GO
    SET ANSI_WARNINGS OFF
    GO
    Should resolve the problem, which it does but for some reason after I've altered the Stored Procedure to include it and reopen the SP, SET ARITHABORT OFF
    GO
    SET ANSI_WARNINGS OFF
    GO is no longer there. I'm not sure what I'm missing or are there other ways to resolve the error message?

    Thank you in advance!

    Put

    case when column1=0 then 1 else column1 end

    instead of the column to avoid the error.


    Many Thanks & Best Regards, Hua Min

    Thursday, April 11, 2013 9:39 AM
  • you can eradicate this error by implementing case statments where you are using divide operation like,

    case when sum(xyz)=0 then 0 else sum(abc)/sum(xyz) end........

    .............

    Thursday, April 11, 2013 9:44 AM
  • Just to clarify the answers given.  You need to change your code to check for the 0 and not attempt to divide by 0.  You cannot solve this using SET options.

    Thursday, April 11, 2013 3:48 PM
    Moderator