Subject Re: [firebird-support] help with a select, please!
Author Sergio H. Gonzalez
Thank you very much Fidel & Dimitry!!

> Hum... I see. You are trying to create a hierarquical tree of
> accounts, and then you want to get the balance on each one.

Yup! that's exactly what I want!!

> create table account (
> id bigint not null primary key,
> parent_id references account (id),
> code varchar(6),
> description not null varchar(60),
> allows_entries boolean /* Declare boolean as a domain of type
> char(1) or short */
> );

Yes! that's almost the same structue I have...

> Now, in your journal entry form, you will select only the accounts
> that have allows_entries equal 1.

Well, yes, but not *all* the accounts that allows entries... depending the
account I'm analizing... what I want is: all the "childs" of that account, and
all the "childs of the childs", and all the "childs of the childs of the
childs"... and so on :)

In my previous example, as want the balance of the account 1400, I need to
select the accounts:

1410
1421
1422

> In order to get the balances (or summaries as you call it), you can do
> two things:
>
> 1) if you are using FB 2.1.x, then use recursive CTEs
> 2) if you are using a version that does not support CTEs, then use a
> stored procedure

I use FB2.1 and I think a recursive select is what I need, the problem is that I
never used that before, and I don't have a clue about how to start...

I don't imagine how to do it on the client side (as Dimitry says), because I
don't know how to select the records I need...

Thanks again guys!!!