Subject | Force NULL to zero in calculation? |
---|---|
Author | Joe Martinez |
Post date | 2004-08-17T16:57:08Z |
Take the following query:
select (saleprice-salecost-saletradein) as Profit
from sales where saledate = '08/08/04'
The problem is that if saletradein is NULL, then the resulting Profit is
also null. That's not what I want. If saletradein is null, I want it to
assume zero for that field. For instance 100 - 25 - NULL = 75. I know
that logically, that's not technically correct, but that's the effect that
I want.
Is there any way to write the query so that it works that way?
-Joe
select (saleprice-salecost-saletradein) as Profit
from sales where saledate = '08/08/04'
The problem is that if saletradein is NULL, then the resulting Profit is
also null. That's not what I want. If saletradein is null, I want it to
assume zero for that field. For instance 100 - 25 - NULL = 75. I know
that logically, that's not technically correct, but that's the effect that
I want.
Is there any way to write the query so that it works that way?
-Joe