Re: How to avoid divide by zero errors?

From: andrija <andrija.rubelj_at_konzum.hr>
Date: 25 Mar 2002 01:39:50 -0800
Message-ID: <4bcceb3d.0203250139.45af2c4c_at_posting.google.com>


laredotornado_at_zipmail.com (D. Alvarado) wrote in message news:<9fe1f2ad.0203241700.4d6b84c_at_posting.google.com>...
> Hello,
>
> I have a table with some columns,
>
> COLUMN1 COLUMN2
> ------- -------
> 4 2
> 3 0
> 5 1
> 10 0
> 15 30
>
> I would like to execute the statement "SELECT COLUMN1 / COLUMN2 from
> MY_TABLE", but if I execute this statement, I get divisor is equal to
> zero errors. However, I don't want to discount columns where the
> divisor is equal to zero (e.g. "SELECT COLUMN1 / COLUMN2 from MY_TABLE
> WHERE COLUMN2 > 0"), rather, I'd like the result of that column to be
> a special number, say -1 or 0 or something. For example, it would be
> great if my result set looked like:
>
> COLUMN1 / COLUMN2
> -----------------
> 2
> -1
> 5
> -1
> .5
>
> Can this be done? How?
>
> thanks, Dave A.

select column1/column2 as x
from my_table
where column2<>0
union
select "-1" as x
from my_table
where column2=0 Received on Mon Mar 25 2002 - 10:39:50 CET

Original text of this message