How to fix "Divide by zero error" in SQL Server

  • Derrick Leggett (6/22/2004)


    Don't divide by zero. <img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'> You need to figure out where you are doing this and fix it.

    BWAAA-HAAA!!!! Even if this thread is more than a decade old, I saw the title of this thread and I knew what my answer would be. You beat me too it and I had a great laugh after a tough day. 🙂

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • nigel. (2/26/2010)


    Guys you're posting answers to a question asked in 2004. I hope they've fixed the problem by now. :w00t:

    It's now more than a decade and if they're anything like the people I've been interviewing lately, the I'd have to say "probably not". 😛

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Luis Cazares (11/6/2015)


    priterande (11/5/2015)


    select COALESCE(MIN(Act) / NULLIF(MAX(Act),0), 0) as minvsmaxAct from table_name

    This is what I usually do, except that I don't reply to 5 year old threads. :w00t:

    I usually don't care when a thread started... especially if someone has a better idea.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • You can also do this

    SELECT Dividend / ISNULL(NULLIF(Divisor,0),1) AS Result

Viewing 4 posts - 16 through 18 (of 18 total)

You must be logged in to reply to this topic. Login to reply