How to join (ap invoice distributions all) AP table info with PO Table

注: 转自http://www.cnblogs.com/benio/archive/2011/01/06/1928932.html

 


Below is the SQL for AP->PO->SLA->GL  for *R12*.

 

select ph.segment1 po_number,
       aps.vendor_name,
       msi.segment1 item_number,
       msi.description item_description,
      
       'A/P PO Match' accrual_transaction,
       'AP*' source,
       (select organization_name
          from apps.org_organization_definitions
         where organization_id = pd.destination_organization_id)
      
       org,
       ai.invoice_num doc_number,
       ai.invoice_date doc_date,
       aid.invoice_line_number line,
       pl.unit_meas_lookup_code uom,
      
       aid.quantity_invoiced quantity,
       aid.unit_price,
       (nvl(xdl.unrounded_accounted_dr, 0) -
       nvl(xdl.unrounded_accounted_cr, 0)) accounted_amount,
       (nvl(xdl.unrounded_entered_cr, 0) - nvl(xdl.unrounded_entered_cr, 0)) entered_amount,
       xal.currency_code
  from apps.gl_je_headers                gjh,
       apps.gl_je_lines                  gjl,
       apps.gl_import_references         gir,
       apps.xla_ae_lines                 xal,
       apps.xla_ae_headers               xah,
       apps.xla_events                   xe,
       apps.xla_event_types_tl           xet,
       apps.xla_event_classes_tl         xect,
       apps.xla_distribution_links       xdl,
       apps.ap_invoice_distributions_all aid,
       apps.ap_invoices_all              ai,
       apps.po_headers_all               ph,
       apps.po_distributions_all         pd,
       apps.po_lines_all                 pl,
       apps.ap_suppliers                 aps,
       apps.mtl_system_items_b           msi
 where gjh.je_header_id = gjl.je_header_id
   and gjh.je_header_id = gir.je_header_id
   and gjl.je_header_id = gir.je_header_id
   and gir.je_line_num = gjl.je_line_num
   and gir.gl_sl_link_id = xal.gl_sl_link_id
   and xal.ae_header_id = xah.ae_header_id
   and xah.event_id = xe.event_id
   and xe.event_type_code = xet.event_type_code
   and xe.application_id = xet.application_id
   and xet.language = userenv('LANG')
   and xect.entity_code = xet.entity_code
   and xect.event_class_code = xet.event_class_code
   and xect.application_id = xe.application_id
   and xect.language = userenv('LANG')
   and xah.ae_header_id = xdl.ae_header_id
   and xal.ae_line_num = xdl.ae_line_num
   and xdl.source_distribution_type = 'AP_INV_DIST'
   and xdl.source_distribution_id_num_1 = aid.invoice_distribution_id
   and ai.invoice_id = aid.invoice_id
   and aid.po_distribution_id = pd.po_distribution_id
   and gjh.je_source = 'Payables'
   and ph.po_header_id = pd.po_header_id
   and pl.po_header_id = ph.po_header_id
   and pd.po_line_id = pl.po_line_id
   and pd.org_id = &org_id
   and ph.org_id = &org_id
   and ai.org_id = &org_id
   and aid.org_id = &org_id
   and gjl.code_combination_id = &ccid
   and ph.vendor_id = aps.vendor_id
   and msi.inventory_item_id = pl.item_id
   and msi.organization_id = pd.destination_organization_id

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值