Subject | Re: [firebird-support] Force NULL to zero in calculation? |
---|---|
Author | Lucas Franzen |
Post date | 2004-08-17T17:09:22Z |
Joe Martinez schrieb:
select
(
COALESCE ( saleprice, 0 ) -
COALESCE ( salecost, 0 ) -
COALESCE ( -saletradein, 0 )
) as Profit
from sales where saledate = '08/08/04'
set them to 0 when insering / updating.
This will save you a lot of trouble...
Luc.
> Take the following query:If you use FB1.5 you can do:
>
> select (saleprice-salecost-saletradein) as Profit
> from sales where saledate = '08/08/04'
select
(
COALESCE ( saleprice, 0 ) -
COALESCE ( salecost, 0 ) -
COALESCE ( -saletradein, 0 )
) as Profit
from sales where saledate = '08/08/04'
>You should define columns like that as NOT NULL and / or use triggers to
> 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.
set them to 0 when insering / updating.
This will save you a lot of trouble...
Luc.