追溯AR收款核销的日记账的SQL

问题描述:
如何用SQL从应收的收款核销追溯到该核销生成的日记账

解决方法
可以用如下SQL
SELECT cr.receipt_number,
cr.cash_receipt_id,
arp.receivable_application_id,
xal.entered_dr,
xal.entered_cr,
xal.code_combination_id,
xah.event_id,
xal.ae_header_id
FROM ar_cash_receipts_all cr,
ar_receivable_applications_all arp,
ar_distributions_all ard,
xla_ae_headers xah,
xla_ae_lines xal,
xla_events xet,
xla_distribution_links xdl,
gl_code_combinations gcc
WHERE xal.ae_header_id = xah.ae_header_id
AND xet.event_id = xah.event_id
AND xdl.event_id = xet.event_id
AND xdl.ae_header_id = xah.ae_header_id
AND xdl.ae_line_num = xal.ae_line_num
AND xdl.source_distribution_type IN (‘AR_DISTRIBUTIONS_ALL’,
‘MFAR_DISTRIBUTIONS_ALL’)
AND xdl.source_distribution_id_num_1 = ard.line_id
AND ard.source_id = arp.receivable_application_id
AND ard.source_table = ‘RA’
AND xdl.application_id = 222
AND arp.cash_receipt_id = cr.cash_receipt_id
AND cr.cash_receipt_id = :receipt_id
AND gcc.code_combination_id = xal.code_combination_id
AND gcc.segment1 != ‘00000000000000’
参考信息
SQL中各表的连接关系如下图:
追溯AR收款核销的日记账的SQL