SELECT 'AP: '||ai.invoice_type_lookup_code je_source, ---AP_INVOICES gjb.name batch_name, gjh.je_header_id, gjl.je_line_num, gcc.segment2 product_line, gcc.segment3 channel, gcc.segment4 cost_center, gcc.segment5 account, ftl.description acct_description, decode(nvl(xdl.UNROUNDED_ACCOUNTED_DR,0),0,(-1) * xdl.UNROUNDED_ACCOUNTED_CR,xdl.UNROUNDED_ACCOUNTED_DR) amount, gjh.default_effective_date gl_date, gjl.description description, v.segment1 vendor_num, v.vendor_name, ai.invoice_date, ai.invoice_num, gjh.currency_code, gjh.period_name FROM apps.gl_code_combinations gcc, apps.fnd_flex_values ffv, apps.fnd_flex_values_tl ftl, apps.gl_je_lines gjl, apps.gl_je_headers gjh, apps.gl_je_batches gjb, apps.gl_import_references gir, apps.xla_ae_headers xah, apps.xla_ae_lines xal, apps.xla_distribution_links xdl, apps.xla_events xe, apps.xla_transaction_entities_upg xte, apps.ap_invoices_all ai, apps.ap_suppliers v WHERE ffv.flex_value_set_id(+) = 1008860 AND gcc.code_combination_id = gjl.code_combination_id AND gcc.segment5 = ffv.flex_value(+) AND ffv.flex_value_id = ftl.flex_value_id(+) AND ftl.language(+) = 'US' AND ftl.source_lang(+) = 'US' AND gjh.je_batch_id = gjb.je_batch_id AND gjl.je_header_id = gjh.je_header_id AND gjh.ledger_id = 1 AND gjh.je_source = 'Payables' AND GJH.JE_CATEGORY='Purchase Invoices' and (gjl.accounted_cr!=0 or gjl.accounted_dr!=0) AND gjl.je_header_id = gir.je_header_id AND gjl.je_line_num = gir.je_line_num AND gjh.je_header_id = gir.je_header_id AND gir.gl_sl_link_table = xal.gl_sl_link_table AND gir.gl_sl_link_id = xal.gl_sl_link_id AND xah.ae_header_id = xal.ae_header_id AND gjl.code_combination_id = xal.code_combination_id AND xah.ae_header_id = xdl.ae_header_id AND xal.ae_line_num = xdl.ae_line_num AND xdl.event_id = xe.event_id AND xe.entity_id = xte.entity_id AND xte. entity_code = 'AP_INVOICES' AND xte.source_id_int_1 = ai.invoice_id AND ai.vendor_id = v.vendor_id --Comment the where conditions -- AND GJH.PERIOD_NAME='OCT-11' -- and gjl.code_combination_id=82772 --and gjh.period_name='NOV-11' UNION ALL SELECT 'AP: '||gjh.je_category je_source, ---AP_CHECKS gjb.name batch_name, gjh.je_header_id, gjl.je_line_num, gcc.segment2 product_line, gcc.segment3 channel, gcc.segment4 cost_center, gcc.segment5 account, ftl.description acct_description, decode(nvl(xdl.UNROUNDED_ACCOUNTED_DR,0),0,(-1) * xdl.UNROUNDED_ACCOUNTED_CR,xdl.UNROUNDED_ACCOUNTED_DR) amount, gjh.default_effective_date gl_date, 'Check Num:'||ac.CHECK_NUMBER description, v.segment1 vendor_num, v.vendor_name, null invoice_date, null invoice_num, gjh.currency_code, gjh.period_name FROM apps.gl_code_combinations gcc, apps.fnd_flex_values ffv, apps.fnd_flex_values_tl ftl, apps.gl_je_lines gjl, apps.gl_je_headers gjh, apps.gl_je_batches gjb, apps.gl_import_references gir, apps.xla_ae_headers xah, apps.xla_ae_lines xal, apps.xla_distribution_links xdl ,apps.AP_PAYMENT_HIST_DISTS aphd ,apps.ap_payment_history_all aph ,apps.ap_checks_all ac ,apps.ap_suppliers v WHERE ffv.flex_value_set_id(+) = 1008860 AND gcc.code_combination_id = gjl.code_combination_id AND gcc.segment5 = ffv.flex_value(+) AND ffv.flex_value_id = ftl.flex_value_id(+) AND ftl.language(+) = 'US' AND ftl.source_lang(+) = 'US' AND gjh.je_batch_id = gjb.je_batch_id AND gjl.je_header_id = gjh.je_header_id AND gjh.ledger_id = 1 AND gjh.je_source = 'Payables' AND gjl.je_header_id = gir.je_header_id AND gjl.je_line_num = gir.je_line_num AND gir.gl_sl_link_table = xal.gl_sl_link_table AND gir.gl_sl_link_id = xal.gl_sl_link_id AND xah.ae_header_id = xal.ae_header_id AND xah.application_id=xal.application_id AND gjl.code_combination_id = xal.code_combination_id AND xal.ae_header_id = xdl.ae_header_id AND xal.ae_line_num = xdl.ae_line_num and GJH.je_category='Payments' and (gjl.accounted_cr!=0 or gjl.accounted_dr!=0) and xdl.source_distribution_id_num_1(+)=aphd.PAYMENT_HIST_DIST_ID and aphd.payment_history_id(+)=aph.payment_history_id and aph.check_id(+)=ac.check_id and ac.vendor_id=v.vendor_id --Comment the below condition --and gjl.code_combination_id=82772 --and gjh.period_name='NOV-11'