Subject | Re: [firebird-support] How to create an calculated field for bank balance? |
---|---|
Author | Alexandre Benson Smith |
Post date | 2012-09-12T19:29:29Z |
Em 12/9/2012 15:28, K Z escreveu:
It depends on the date range selected, the order of the records stored,
and so on...
IMHO it's a dynamic thing that must be calculated on the fly.
> Hello,I would implement it on the client side...
>
>
> Is there a trick to have this?
>
> CREATE TABLE BANK_ACCOUNT
> (
> ID INTEGER NOT NULL,
> OCCURRENCE TIMESTAMP,
> DESCRIPTION VARCHAR(100),
> AMOUNT DECIMAL(10,2) NOT NULL
> CONSTRAINT PK_
> BANK_ACCOUNT _1 PRIMARY KEY (ID)
> );
>
>
>
> CREATE VIEW BANK_ACCOUNT_STATEMENT (ID,
> OCCURRENCE ,
> DESCRIPTION , AMOUNT, BALANCE)
> AS
>
> SELECT r.*, (Calculated Field)
> as BALANCE
> FROM
> BANK_ACCOUNT r
> order by r.OCCURRENCE
> desc
> ;
>
>
> Calculated Field is the previous record balance plus the current record field AMOUNT. If there is no previous record, then is the current record field AMOUNT.
>
> For example:
> ID DESCRIPTION AMOUNT BALANCE
> 1 Deposit 10 10
> 2 Check -5 5
> 3 Check -10 -5
> 4 Credit transfer 50 45
>
> Thank you in advance for your support.
>
>
It depends on the date range selected, the order of the records stored,
and so on...
IMHO it's a dynamic thing that must be calculated on the fly.