i have a query that in a sub query calculates amount by dividing two of the columns. I get this error that i have division by zero, but actually i don’t have 0 or NULL values. Here is the query:
SELECT
(SELECT ISNULL((IznosIni/VrednostIni),0)
from plPlataF f1
where plPresmetka_id in
(select plPresmetka_id from plPresmetka where f_vlezno=1 and Kod ='01')
and f1.plPlataS_id=s.plPlataS_id)
FROM plPlataS s
WHERE plPlataH_Id = 171
when i run this query (i only concatenate the two values with ‘—‘ in between)
SELECT
(SELECT CONVERT(NVARCHAR(20),IznosIni)+'---'+CONVERT(NVARCHAR(20),VrednostIni)
from plPlataF f1
where plPresmetka_id in
(select plPresmetka_id from plPresmetka where f_vlezno=1 and Kod ='01')
and f1.plPlataS_id=s.plPlataS_id)
FROM plPlataS s
WHERE plPlataH_Id = 171
i get results :
32414.00---168.00
37613.00---168.00
31341.00---168.00
49148.00---168.00
110507.00---168.00
36601.00---168.00
37895.00---168.00
59699.00---168.00
43978.00---168.00
50991.00---168.00
36601.00---168.00
48087.00---168.00
45921.00---168.00
59499.00---168.00
37613.00---168.00
37613.00---168.00
34850.00---168.00
33632.00---168.00
33632.00---168.00
There is no 0 anywhere!!!
Can someone please help i don’t understand what the problem might be.
Thanks in advance.
Since you are using
ISNULL, I’m guessing this is TSQL. You should always take into account on division about the possibility of dividing by zero. You can useNULLIFfor this: