warrenk Posted February 22, 2007 Share Posted February 22, 2007 I have a SQL that has divide by zero errors. Is there anyway to prevent this? update ix_spc_product set Desc6 = CHAR(@FISCAL_MONTH), Value1 = @T_UNITS_SOLD_LM, Value2 = @T_DOLLARS_SOLD_LM, Value3 = (@T_DOLLARS_SOLD_LM - @T_COST_LM), Value4 = (@T_DOLLARS_SOLD_LM - @T_COST_LM) / @T_DOLLARS_SOLD_LM, Value5 = @T_UNITS_SOLD_6M, Value6 = @T_DOLLARS_SOLD_6M, Value7 = (@T_DOLLARS_SOLD_6M - @T_COST_6M), Value8 = (@T_DOLLARS_SOLD_6M - @T_COST_6M) / @T_DOLLARS_SOLD_6M, Value9 = @T_UNITS_SOLD_12M, Value10 = @T_DOLLARS_SOLD_12M, Value11 = (@T_DOLLARS_SOLD_12M - @T_COST_12M), Value12 = (@T_DOLLARS_SOLD_12M - @T_COST_12M) / @T_DOLLARS_SOLD_12M, Value13 = @T_UNITS_SOLD_LY, Value14 = @T_DOLLARS_SOLD_LY where ID = @ITEM_NUMBER Quote Link to comment https://forums.phpfreaks.com/topic/39646-divide-by-zero-error/ Share on other sites More sharing options...
fenway Posted February 22, 2007 Share Posted February 22, 2007 Like checking your denominator with an IF()? Quote Link to comment https://forums.phpfreaks.com/topic/39646-divide-by-zero-error/#findComment-191392 Share on other sites More sharing options...
warrenk Posted February 22, 2007 Author Share Posted February 22, 2007 Can I use a CASE statement in a SET? Or is this not possible? update ix_spc_product set Desc6 = CHAR(@FISCAL_MONTH), Value1 = @T_UNITS_SOLD_LM, Value2 = @T_DOLLARS_SOLD_LM, Value3 = (@T_DOLLARS_SOLD_LM - @T_COST_LM), Case @T_DOLLARS_SOLD_LM WHEN 0 Value4 = 0 ELSE Value4 = (@T_DOLLARS_SOLD_LM - @T_COST_LM) / @T_DOLLARS_SOLD_LM END Value5 = @T_UNITS_SOLD_6M, Value6 = @T_DOLLARS_SOLD_6M, Value7 = (@T_DOLLARS_SOLD_6M - @T_COST_6M), Value8 = (@T_DOLLARS_SOLD_6M - @T_COST_6M) / @T_DOLLARS_SOLD_6M, Value9 = @T_UNITS_SOLD_12M, Value10 = @T_DOLLARS_SOLD_12M, Value11 = (@T_DOLLARS_SOLD_12M - @T_COST_12M), Value12 = (@T_DOLLARS_SOLD_12M - @T_COST_12M) / @T_DOLLARS_SOLD_12M, Value13 = @T_UNITS_SOLD_LY, Value14 = @T_DOLLARS_SOLD_LY where ID = @ITEM_NUMBER Quote Link to comment https://forums.phpfreaks.com/topic/39646-divide-by-zero-error/#findComment-191417 Share on other sites More sharing options...
fenway Posted February 22, 2007 Share Posted February 22, 2007 Sure, I don't see why not. Quote Link to comment https://forums.phpfreaks.com/topic/39646-divide-by-zero-error/#findComment-191555 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.