Help w/ algoritm to order table
Posted in 1996
Hi there, I'm presently working on an accounting software, and came across the following problem: Among other, the database has an "accounts" table and a "movements" table. The structure is as follows: ACCOUNTS MOVEMENTS code char(10) acctcode char(10) type char amount dec(10,2) Some sample data, could be: ACCOUNTS MOVEMENTS code type acctcode amount 1 T 111 1500 11 T 111 3000 111 M 111 -1500 112 M 12111 3000 12 T 12111 4000 121 T 12111 M 12112 M In the "accounts" table type means: T - This account acumulates the amounts of the accounts underneath (11 acumulates the amounts of 111 and 112) and can't be used on "movements" V - This is an account that can be used on "movements" Note that, 12111 is under 121 and not 1211. What i pretend is to generate an output that looks like: Acct Total 111 4000 112 0 11 4000 12111 7000 12112 0 121 7000 12 7000 1 11000 Any ideas would be appreciated. TIA JN