Jonathan Keebler

Preventing Division by Zero in SQL Calls (and Megan Fox)

Okay, I know this is uber-geek so no need to mention that in the comments :D But I was searching for an easy way to prevent division by zero in a division operation in a (MS)SQL SELECT statement, and this popped out as a great way to do so. Use at your own risk of also being branded a geek, and being forced into a world of Star Trek collectables ;-)

ISNULL( NULLIF( your_field, 0 ), 1 )


Comments RSS Both comments and pings are currently closed.

7 Responses to “Preventing Division by Zero in SQL Calls (and Megan Fox)”

  1. blog-j says:

    Sexy Sql Tip

    Monsieur Keebler has a quick little post on avoiding divide by zero errors in Sql.
    Coupled with some fairly… warm and fuzzy … imagery of the foxy Megan Fox.
    Have a read (and look) over @ keebler.net

  2. Fuzzzy says:

    I for one welcome our non-divisible-by-zero overlords :)

  3. Jonathan says:

    I hear when you divide by zero, God kills a kitten.

  4. MrHappy says:

    I heard that when you divide by zero the client kills a developer. I, however, have proof against this. You know what I’m talking about.

  5. Jonathan says:

    Bill for another 8 hours? :D

  6. dasd says:

    so beatifull

  7. MP says:

    DECLARE @x VARCHAR(10)
    SET @x = ”
    SELECT @x/0 –divide-by-zero error
    SELECT ISNULL( NULLIF( @x, 0 ), 1 )/0 –ditto!!!