Subject RE: [firebird-support] "divison by 0" question
Author Alan McDonald
>
> I have a query that looks something like:
> SELECT
> S.PRICE SALEPRICE,
> E.PRICE ENTRYPRICE,
> (S.PRICE -I.PRICE)/I.PRICE PERCENT
> FROM SALES S, ENTRYS E
> WHERE S.IDENTRY = E.ID
>
> The problem is that I.PRICE can be 0 and i get a division by 0 error. Is
> there a way to make PERCENT = 100 if I.PRICE = 0 without running
> two querys?
>

> SELECT
> S.PRICE SALEPRICE,
> E.PRICE ENTRYPRICE,
CASE WHEN I.PRICE=0
THEN 100
ELSE
> (S.PRICE -I.PRICE)/I.PRICE
END PERCENT
> FROM SALES S, ENTRYS E
> WHERE S.IDENTRY = E.ID

Alan