Thursday, October 11, 2018

Retrieve Billing Date from the Billing Schedule table

When extracting billing_schedule table, there is no billing_date column. A workaround is to join transactions and transaction_lines tables and use the date_closed column. Below is a sample query

select transaction_id,date_closed as date ,-sum(amount_foreign) as amount
from transaction_lines
INNER JOIN TRANSACTIONS ON TRANSACTION_LINES.TRANSACTION_ID = TRANSACTIONS.TRANSACTION_ID
where
TRANSACTIONS.TRANSACTION_TYPE='Sales Order'
AND account_id is not null
and transaction_line_id != 0
and tax_type is null
and item_count != 0
and date_closed is not null
and (date_closed between to_date ('2011/01/01', 'yyyy/mm/dd')AND to_date ('2014/12/31', 'yyyy/mm/dd'))
and not exists ( select 0 from billing_schedule
where transaction_lines.transaction_id = billing_schedule.transaction_id
and transaction_lines.transaction_line_id = billing_schedule.transaction_line_id )
GROUP BY date_closed,transaction_id

No comments:

Post a Comment