View Full Version : Division by zero error


Mike Hughes
11-13-2009, 02:25 AM
I have the query below and keep getting "Division by Zero" error when I run it.
I'm looking for the percent of CURRENT PAID to the CURRENT DUE. There is one CASELOAD which has "0" CURRENT DUE AND "0" CURRENT PAID and I believe that might be what is causing the problem.
Can someone point me in the right direction? Thanks

SELECT
[14 TABLE].CASELOAD,
[14 TABLE].[CURR DUE],
[14 TABLE].[CURR PAID],
[14 TABLE].[ARR PAID],
SUM ([14 TABLE].[CURR PAID]/[14 TABLE].[CURR DUE]) AS [PERCENT PAID]

FROM [14 TABLE]
GROUP BY
[14 TABLE].CASELOAD,
[14 TABLE].[CURR DUE],
[14 TABLE].[CURR PAID],
[14 TABLE].[ARR PAID]

GalaxiomAtHome
11-13-2009, 02:36 AM
After the From line add
Where [CURR DUE] <> 0

Another way is to use an IIF statement.

IIF ([CURR DUE] <> 0, SUM([CURR PAID]/[[CURR DUE]), Null) AS [PERCENT PAID]

Where there is only one table you can leave out the table name.
Also recommend you stop using all capitals for fields and stop including spaces.
CurrentDue is a lot easier to read and enter.

KenHigg
11-13-2009, 02:37 AM
One option would be to eliminate the row where the zero occurs with a parameter. Something like show me all the rows where so and so field is not zero...

KenHigg
11-13-2009, 02:38 AM
Galaxi beat me to the punch :p

Mike Hughes
11-13-2009, 02:49 AM
Thanks to all
I went with GalaxiomAtHome-- "Where [CURR DUE] <> 0"