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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Division by 0 error, where's the problem?

Author  Topic 

mmccardle
Starting Member

43 Posts

Posted - 2010-06-30 : 15:32:06
I'm building a stored procedure for a report and I'm getting a division by zero error. There is only one division problem in the SP:

ROUND(CASE WHEN onhand > 0 OR
(onhand - threesixtyfivedaysupply + threesixtyfivedayusage) > 0 --BEGINNING BALANCE
THEN threesixtyfivedayusage/(((onhand)+(onhand - threesixtyfivedaysupply + threesixtyfivedayusage))/2)
ELSE 0 END,2) AS '12monthturns'

I thought I had solved the division by zero error with the CASE statement but that apparently is not working.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-30 : 16:14:48
onhand + onhand?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

mmccardle
Starting Member

43 Posts

Posted - 2010-06-30 : 16:17:49
Its a report to find inventory turns, which is calculated by "usage/(ending balance + beginning balance)/2"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-30 : 16:42:30
THEN threesixtyfivedayusage/(((onhand)+(onhand - threesixtyfivedaysupply + threesixtyfivedayusage))/2)


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

mmccardle
Starting Member

43 Posts

Posted - 2010-06-30 : 16:46:28
nvm, one value was -5 and the other was 5, thus creating a 0/2 and thus a x/0 error.
Go to Top of Page
   

- Advertisement -