How to avoid divide by zero
----------------------------------------------------------------------------------
SELECT CASE WHEN field2 = 0 THEN 0 ELSE field1 / field2
FROM table
or
SELECT field1 / ( field2 * CONVERT( int, SUBSTRING( '1', 1, ABS( SIGN( field2 ) ) ) ) )
FROM table
No comments:
Post a Comment