Subject Re: [ib-support] Count value on field
Author Helen Borrie
At 08:33 PM 20-03-02 +0700, you wrote:
>Using FireBird 1.0.0 796 on Windows 98
>
>I have meta data like this
>
>CREATE DOMAIN NUMERIC_17_2 AS
>NUMERIC(17,2)
>/* can be fill with null values */
>
>CREATE TABLE TRANSAKSI (
> ID NUMERIC(18,0) NOT NULL,
> D_IMIP NUMERIC_17_2,
> D_SVIP NUMERIC_17_2,
> D_CDIP NUMERIC_17_2,
> JUMLAH_DEBET COMPUTED BY (D_IMIP+D_SVIP+D_CDIP));
>
>This table have two records with this value
>
>D_IMIP D_SVIP D_CDIP
>1000.26 null null
>null 150.36 100.00
>
>What i want is the calculated field jumlah_debet will give 1000.26 result,
>but in this fields give me null results.
>
>I try statement like this
>
>select sum(d_imip)
>give me 1000.26 results
>
>select d_imip+d_svip+d_cdip from transaksi
>give me null results
>
>Any advice how to get results on this computed fields (remember that the
>fields d_imip,d_svip,d_cdip can
>fill with null values )

Quite simply, it makes no sense to created a computed column that performs
a calculation on nullable columns, *unless* you want the computed to column
to be null if any of its elements is null. You will need to make these
columns not null and default them to zero, i.e. 0.00. If you want to keep
your domain as nullable, then apply the DEFAULT constraint at column level
or, better, do it with triggers (BI and BU) and enforce it with a CHECK
constraint.

cheers,
H.

All for Open and Open for All
Firebird Open SQL Database · http://firebirdsql.org ·
http://users.tpg.com.au/helebor/
_______________________________________________________