You are on page 1of 4

SELECT

okh.contract_number,
okh.sts_code contract_header_status,
okl.line_number,
okl.id contract_lineid,
okl.sts_code contract_line_status,
okh.attribute11 web_contract_number,
okh.attribute10 sf_header_id,
(
SELECT
name
FROM
hr_operating_units
WHERE
organization_id = okh.authoring_org_id
) leg_entity_name,
okh.currency_code,
okh.start_date header_start_date,
okh.end_date header_end_date,
hca.account_number,
hcsua.location ship_to_location_code,
hcsua1.location bill_to_location_code,
(
SELECT
name
FROM
qp_list_headers
WHERE
list_header_id = okh.price_list_id
) price_list_name,
(
SELECT
a.name
FROM
ra_terms a
WHERE
a.term_id = okh.payment_term_id
AND a.end_date_active IS NULL
) payment_term,
okh.attribute12 billing_uom,
okl.attribute10 sf_line_id,msi.segment1 subscription_item,oki.number_of_items
sub_quantity,
round (okl.price_negotiated) price_negotiated,
okl.start_date line_start_date,
okl.end_date line_end_date
FROM
okc_k_headers_all_b okh,
okc_k_lines_b okl,
hz_cust_site_uses_all hcsua,
hz_cust_site_uses_all hcsua1,
hz_cust_accounts_all hca,
hz_cust_acct_sites_all hcasa,
okc_k_items oki, mtl_system_items_B msi
WHERE
okh.id = okl.chr_id
AND hcsua.site_use_code = 'SHIP_TO'
AND hcsua.site_use_id = okh.ship_to_site_use_id
AND hcsua1.site_use_code = 'BILL_TO'
AND hcsua1.site_use_id = okh.bill_to_site_use_id
AND hca.cust_account_id = hcasa.cust_account_id
AND hcsua.cust_acct_site_id = hcasa.cust_acct_site_id
AND hcsua.site_use_id = okh.ship_to_site_use_id
and oki.dnz_chr_id=okh.id
and oki.cle_id=okl.id
and msi.inventory_item_id=oki.object1_id1
and msi.organization_id=106
AND okh.attribute10 in
(select sf_header_id from xx3d_oks_cpq_sc_header_stg where record_status='P'
and sf_header_id like '80%')
--------
SELECT
ooh.order_number,
ooh.flow_status_code,
ool.line_number order_line_number,
ool.line_id,
ooh.attribute1 web_order_number,
ooh.attribute13 sf_header_id,
(
SELECT
name
FROM
hr_operating_units
WHERE
organization_id = ooh.org_id
) entity_name,
hca.account_number,
ooh.fob_point_code,
hcsua.location ship_to_location,
hcsua1.location bill_to_location,
ooh.transactional_curr_code,
ooh.ordered_date,
ooh.request_date,
ooh.pricing_date,
(
SELECT
nvl(
jrs.email_address, jrd.source_email
)
FROM
jtf_rs_salesreps jrs,
jtf_rs_defresources_v jrd
WHERE
jrs.resource_id = jrd.resource_id
AND salesrep_id = ooh.salesrep_id
AND jrs.org_id = ooh.org_id
) sales_person,
(
SELECT
name
FROM
qp_list_headers
WHERE
list_header_id = ooh.price_list_id
) price_list_name,
(
SELECT
a.name
FROM
ra_terms a
WHERE
a.term_id = ooh.payment_term_id
AND a.end_date_active IS NULL
) payment_term,
(
SELECT
SUM(ordered_quantity * unit_selling_price) + SUM(tax_value)
FROM
oe_order_lines_all
WHERE
header_id = ooh.header_id
) amount,
(
SELECT
SUM(ordered_quantity * unit_selling_price)
FROM
oe_order_lines_all
WHERE
header_id = ooh.header_id
) sub_total,
(
SELECT
SUM(ordered_quantity * unit_selling_price) + SUM(tax_value)
FROM
oe_order_lines_all
WHERE
header_id = ooh.header_id
) total,
ooh.attribute6 invoice_dispatch_method,
ooh.attribute7 invoice_dispatch_details,
ooh.attribute8
acknowledgement_dispatch_details,
ooh.freight_terms_code,
ooh.cust_po_number,ool.attribute13 sf_line_id,
ool.ordered_item,
ool.unit_selling_price,
ool.ordered_quantity,
( ool.unit_selling_price * ool.ordered_quantity ) total_line_amount,
ool.service_start_date,
ool.service_end_date,
ool.fob_point_code
FROM
oe_order_headers_all ooh,
oe_order_lines_all ool,
hz_cust_site_uses_all hcsua,
hz_cust_site_uses_all hcsua1,
hz_cust_accounts_all hca,
hz_cust_acct_sites_all hcasa
WHERE
ooh.header_id = ool.header_id
AND hcsua.site_use_code = 'SHIP_TO'
AND hcsua.site_use_id = ooh.ship_to_org_id
AND hcsua1.site_use_code = 'BILL_TO'
AND hcsua1.site_use_id = ooh.invoice_to_org_id
AND hca.cust_account_id = hcasa.cust_account_id
AND hcsua.cust_acct_site_id = hcasa.cust_acct_site_id
AND hca.cust_account_id = ooh.sold_to_org_id
--AND hcsua.site_use_id = ooh.ship_to_site_use_id
AND ooh.attribute13 IN (
SELECT
sf_header_id
FROM
xx3d_om_cpq_header_stg
WHERE
process_flag = 'S' )

ORDER BY
ooh.order_number ASC

----
SELECT
a.web_contract_number,
a.sf_header_id,
b.sf_line_id,
--a.action_type,b.action_type,
a.leg_ent_name,
a.start_date header_start_date,
a.end_date header_end_date,
a.party_name,
a.cust_account_no,
a.ship_to_location,
a.bill_to_location,
a.currency_code,
a.price_list_name,
a.payment_term,
a.billing_uom,
b.item_name,
b.start_date line_start_date,
b.end_date line_end_date,
b.sub_quantity,
b.price_negotiated,
a.contract_number,
a.contract_status conc_header_sts,
b.contract_line_no,
b.contract_line_status conc_line_sts
FROM
xx3d_oks_cpq_sc_header_stg a,
xx3d_oks_cpq_sc_line_stg b
WHERE
a.sf_header_id = b.sf_header_id

You might also like