SELECT DISTINCT su.ROWID, su.site_use_id, su.last_update_date,
su.object_version_number, su.last_updated_by,
su.creation_date, su.created_by, su.site_use_code,
su.cust_acct_site_id address_id, su.primary_flag, su.status,
su.LOCATION, su.last_update_login, su.contact_id,
DECODE (acct_role.cust_account_role_id,
NULL, NULL,
SUBSTRB (party.person_last_name, 1, 50)
|| ', '
|| SUBSTRB (party.person_first_name, 1, 40)
) contact_name,
su.bill_to_site_use_id, su_bill.LOCATION,
su.orig_system_reference, su.sic_code, su.payment_term_id,
term.NAME, su.gsa_indicator, su.ship_partial, su.ship_via,
su.fob_point, su.order_type_id, ordt.NAME, su.price_list_id,
LIST.NAME, su.freight_term, su.warehouse_id, org.NAME,
su.territory_id, su.attribute_category, su.attribute1,
su.attribute2, su.attribute3, su.attribute4, su.attribute5,
su.attribute6, su.attribute7, su.attribute8, su.attribute9,
su.attribute10, su.attribute11, su.attribute12,
su.attribute13, su.attribute14, su.attribute15,
su.attribute16, su.attribute17, su.attribute18,
su.attribute19, su.attribute20, su.attribute21,
su.attribute22, su.attribute23, su.attribute24,
su.attribute25, su.tax_reference, su.tax_code,
su.demand_class_code, hrl.location_id, hrl.location_code,
inv_org.organization_id, inv_org.NAME, su.tax_classification,
su.tax_header_level_flag, su.tax_rounding_rule,
su.global_attribute_category, su.global_attribute1,
su.global_attribute2, su.global_attribute3,
su.global_attribute4, su.global_attribute5,
su.global_attribute6, su.global_attribute7,
su.global_attribute8, su.global_attribute9,
su.global_attribute10, su.global_attribute11,
su.global_attribute12, su.global_attribute13,
su.global_attribute14, su.global_attribute15,
su.global_attribute16, su.global_attribute17,
su.global_attribute18, su.global_attribute19,
su.global_attribute20, su.primary_salesrep_id,
res.resource_name, su.finchrg_receivables_trx_id, rt.NAME,
su.gl_id_rev, su.gl_id_freight, su.gl_id_rec,
su.gl_id_clearing, su.gl_id_tax, su.gl_id_unbilled,
su.gl_id_unearned, su.gl_id_unpaid_rec, su.gl_id_remittance,
su.gl_id_factor, su.dates_negative_tolerance,
su.dates_positive_tolerance, su.date_type_preference,
su.over_shipment_tolerance, su.under_shipment_tolerance,
su.item_cross_ref_pref, su.over_return_tolerance,
su.under_return_tolerance, su.ship_sets_include_lines_flag,
su.arrivalsets_include_lines_flag, su.sched_date_push_flag,
su.invoice_quantity_rule, su.pricing_event, su.org_id
FROM hz_cust_site_uses su,
hz_cust_site_uses su_bill,
ra_terms term,
hz_cust_account_roles acct_role,
hz_parties party,
hz_relationships rel,
hr_all_organization_units org,
so_order_types ordt,
so_price_lists LIST,
po_location_associations pla,
hr_locations hrl,
jtf_rs_salesreps sr,
hr_organization_units inv_org,
ar_receivables_trx rt,
jtf_rs_resource_extns_vl res
WHERE su.bill_to_site_use_id = su_bill.site_use_id(+)
AND su.payment_term_id = term.term_id(+)
AND su.contact_id = acct_role.cust_account_role_id(+)
AND acct_role.party_id = rel.party_id(+)
AND rel.subject_table_name(+) = 'HZ_PARTIES'
AND rel.object_table_name(+) = 'HZ_PARTIES'
AND rel.directional_flag(+) = 'F'
AND acct_role.role_type(+) = 'CONTACT'
AND rel.subject_id = party.party_id(+)
AND su.warehouse_id = org.organization_id(+)
AND su.order_type_id = ordt.order_type_id(+)
AND su.price_list_id = LIST.price_list_id(+)
AND su.site_use_id = pla.site_use_id(+)
AND pla.location_id = hrl.location_id(+)
AND pla.organization_id = inv_org.organization_id(+)
AND su.primary_salesrep_id = sr.salesrep_id(+)
AND sr.resource_id = res.resource_id(+)
AND su.finchrg_receivables_trx_id = rt.receivables_trx_id(+)
su.object_version_number, su.last_updated_by,
su.creation_date, su.created_by, su.site_use_code,
su.cust_acct_site_id address_id, su.primary_flag, su.status,
su.LOCATION, su.last_update_login, su.contact_id,
DECODE (acct_role.cust_account_role_id,
NULL, NULL,
SUBSTRB (party.person_last_name, 1, 50)
|| ', '
|| SUBSTRB (party.person_first_name, 1, 40)
) contact_name,
su.bill_to_site_use_id, su_bill.LOCATION,
su.orig_system_reference, su.sic_code, su.payment_term_id,
term.NAME, su.gsa_indicator, su.ship_partial, su.ship_via,
su.fob_point, su.order_type_id, ordt.NAME, su.price_list_id,
LIST.NAME, su.freight_term, su.warehouse_id, org.NAME,
su.territory_id, su.attribute_category, su.attribute1,
su.attribute2, su.attribute3, su.attribute4, su.attribute5,
su.attribute6, su.attribute7, su.attribute8, su.attribute9,
su.attribute10, su.attribute11, su.attribute12,
su.attribute13, su.attribute14, su.attribute15,
su.attribute16, su.attribute17, su.attribute18,
su.attribute19, su.attribute20, su.attribute21,
su.attribute22, su.attribute23, su.attribute24,
su.attribute25, su.tax_reference, su.tax_code,
su.demand_class_code, hrl.location_id, hrl.location_code,
inv_org.organization_id, inv_org.NAME, su.tax_classification,
su.tax_header_level_flag, su.tax_rounding_rule,
su.global_attribute_category, su.global_attribute1,
su.global_attribute2, su.global_attribute3,
su.global_attribute4, su.global_attribute5,
su.global_attribute6, su.global_attribute7,
su.global_attribute8, su.global_attribute9,
su.global_attribute10, su.global_attribute11,
su.global_attribute12, su.global_attribute13,
su.global_attribute14, su.global_attribute15,
su.global_attribute16, su.global_attribute17,
su.global_attribute18, su.global_attribute19,
su.global_attribute20, su.primary_salesrep_id,
res.resource_name, su.finchrg_receivables_trx_id, rt.NAME,
su.gl_id_rev, su.gl_id_freight, su.gl_id_rec,
su.gl_id_clearing, su.gl_id_tax, su.gl_id_unbilled,
su.gl_id_unearned, su.gl_id_unpaid_rec, su.gl_id_remittance,
su.gl_id_factor, su.dates_negative_tolerance,
su.dates_positive_tolerance, su.date_type_preference,
su.over_shipment_tolerance, su.under_shipment_tolerance,
su.item_cross_ref_pref, su.over_return_tolerance,
su.under_return_tolerance, su.ship_sets_include_lines_flag,
su.arrivalsets_include_lines_flag, su.sched_date_push_flag,
su.invoice_quantity_rule, su.pricing_event, su.org_id
FROM hz_cust_site_uses su,
hz_cust_site_uses su_bill,
ra_terms term,
hz_cust_account_roles acct_role,
hz_parties party,
hz_relationships rel,
hr_all_organization_units org,
so_order_types ordt,
so_price_lists LIST,
po_location_associations pla,
hr_locations hrl,
jtf_rs_salesreps sr,
hr_organization_units inv_org,
ar_receivables_trx rt,
jtf_rs_resource_extns_vl res
WHERE su.bill_to_site_use_id = su_bill.site_use_id(+)
AND su.payment_term_id = term.term_id(+)
AND su.contact_id = acct_role.cust_account_role_id(+)
AND acct_role.party_id = rel.party_id(+)
AND rel.subject_table_name(+) = 'HZ_PARTIES'
AND rel.object_table_name(+) = 'HZ_PARTIES'
AND rel.directional_flag(+) = 'F'
AND acct_role.role_type(+) = 'CONTACT'
AND rel.subject_id = party.party_id(+)
AND su.warehouse_id = org.organization_id(+)
AND su.order_type_id = ordt.order_type_id(+)
AND su.price_list_id = LIST.price_list_id(+)
AND su.site_use_id = pla.site_use_id(+)
AND pla.location_id = hrl.location_id(+)
AND pla.organization_id = inv_org.organization_id(+)
AND su.primary_salesrep_id = sr.salesrep_id(+)
AND sr.resource_id = res.resource_id(+)
AND su.finchrg_receivables_trx_id = rt.receivables_trx_id(+)