Sql query to find the balances for a customer account wise.

Advertisement
Hi,
Could someone help me with the sql query to find the balances for each customer account wise. This is need to generate the report.
presently we are using this query, but the output doesnot return the expected result.
SELECT sum(nvl(ps.acctd_amount_due_remaining,0)) "Balance"
FROM      ra_cust_trx_line_gl_dist_all gld,
          gl_code_combinations c,
          ar_payment_schedules_all ps,
          RA_CUSTOMER_TRX_ALL rat,
          ra_customers rc
WHERE      c.CHART_OF_ACCOUNTS_ID = 101
and gld.code_combination_id = c.code_combination_id
     and rat.CUSTOMER_TRX_ID=gld.CUSTOMER_TRX_ID
     and rat.CUSTOMER_TRX_ID=ps.CUSTOMER_TRX_ID
and ps.customer_id=rc.customer_id
     and ps.status='OP'
     and ps.gl_date <= :PDATE
     and ps.org_id=:PORGID
     and ps.class in ('GUAR','INV','DM','DEP')
and c.SEGMENT4=:Account_id
and ps.customer_id=:Customer_id
Thanks in advance.
Kalyan.
Advertisement

Replay

Can someone help us with this.