Subject Re: [firebird-support] need advice in query...
Author Christian Waldmann
Hello Iwan

Here is a optimsed select in the stored procedure with a order clause to
get the correct order:

for select mut.id, mut.TRANSDATE, mut.DEBET, mut.KREDIT
from TBL_MUTASI mut
order by mut.TRANSDATE
into :ID, :TRANSDATE, :DEBET, :KREDIT


> Hello Iwan
>
> My prefered solution is a stored procedure.
>
> Here is the Table and the stored procedure:
>
> CREATE TABLE TBL_MUTASI (
> ID INTEGER,
> TRANSDATE TIMESTAMP,
> DEBET NUMERIC(15,2),
> KREDIT NUMERIC(15,2)
> );
>
> SET TERM ^ ;
>
> create or alter procedure PROC_CALC_SALDO
> returns (
> ID integer,
> TRANSDATE timestamp,
> DEBET decimal(15,2),
> KREDIT decimal(15,2),
> SALDO decimal(15,2))
> as
> begin
> SALDO = 0;
> for select mut.id, mut.TRANSDATE, mut.DEBET, mut.KREDIT from
> TBL_MUTASI mut
> into :ID, :TRANSDATE, :DEBET, :KREDIT
> do BEGIN
> SALDO = :SALDO + :DEBET - :KREDIT;
> suspend;
> end
> end^
>
> SET TERM ; ^
>
>
> And the select statment:
>
>
> select * from PROC_CALC_SALDO
>
>
> And the result:
>
> ID TRANSDATE DEBET KREDIT SALDO
> 10 03.11.2009 00:00:00 10'000.00 0.00 0'000.00
> 30 05.11.2009 00:00:00 0.00 5'000.00 5'000.00
> 20 04.11.2009 00:00:00 250.00 0.00 5'250.00
>
>
> send2iwan schrieb:
>> hi all,
>>
>> i want to make query like this.
>>
>> table name=mutasi
>>
>> id transdate debet kredit saldo
>> == ========== ===== ====== =====
>> 10 10/01/2009 10000 10000
>> 20 10/05/2009 250 10250
>> 30 10/30/2009 5000 5250
>>
>> how to make the query espesialy for field saldo?
>> everyday records increase 50-200 records.
>>
>> thanks.
>> Iwan
>>
>>
>>
>>
>> ------------------------------------
>>
>> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>
>> Visit http://www.firebirdsql.org and click the Resources item
>> on the main (top) menu. Try Knowledgebase and FAQ links !
>>
>> Also search the knowledgebases at http://www.ibphoenix.com
>>
>> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> Yahoo! Groups Links
>>
>>
>>
>
>
>
> ------------------------------------
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://www.firebirdsql.org and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Yahoo! Groups Links
>
>
>