Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Divide by zero error encountered.

Author  Topic 

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2009-04-06 : 09:59:25
I know this is probably something simple, but for some reason I can not figure it out. I am getting an error message saying "Divide by zero error encountered."

I heard if I just change were it says "5", then The error would stop, but I changed and I am still getting an error. Can anyone shed some light on this for me?

CAST(clm_sppo / clm_tchg * 100 AS decimal(5,2)) AS PCT_of_Savings

Thanks.

Wendy

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-04-06 : 10:03:55
[code]case when clm_tchg=0 then 0 else CAST(clm_sppo / clm_tchg * 100 AS decimal(5,2)) end AS PCT_of_Savings[/code]
Go to Top of Page

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2009-04-06 : 10:05:44
Thanks that worked. the only thing I had to change was my 5 to 10.

case when clm_tchg=0 then 0 else CAST(clm_sppo / clm_tchg * 100 AS decimal(10,2)) end AS PCT_of_Savings
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-06 : 10:37:17
Also try

CAST(COALESCE(clm_sppo / NULLIF(clm_tchg,0),0) * 100 AS decimal(10,2)) AS PCT_of_Savings


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -