[thelist] Avoiding Divide by Zero within SQL...

Rory.Plaire at wahchang.com Rory.Plaire at wahchang.com
Fri Nov 30 15:04:20 CST 2001


+| but if you don't want a null 
+| answer, change the
+| above to
+| 
+|    select
+|        case  coalesce( bar, 0 )
+|           when 0 then 0
+|              else  coalesce( foo / bar, 0 )
+|         end
+|

I thought we were traveling down the path that he was going to convert them
all to 0, but, yea, rudy's code is more robust... the COALESCE is a great
function, and not too expensive.
 
+| both mysql and microsoft's sql/server support it, i'm not sure about
+| oracle, and of course in microsoft access you'd probably use 
+| nested IIFs
+| and ISNULLs
+| 

In Oracle (PL/SQL), you'll use the DECODE function. COALESCE has the
equivalent NVL function.

<rory disposition="that's all I know." alt="8x"/>




More information about the thelist mailing list