Wednesday, June 4, 2014

Query - Customer Details

SELECT DISTINCT hp.party_name "Customer Name",
                hca.account_name "Account Description",
                hou.name "Operating Unit",
                hp.party_number,
                hca.account_number,
                hca.status "Customer Status",
                hps.party_site_number,
                hps.status "Site Status",
                hl.address1,
                hl.address2,
                hl.address3,
                hl.city,
                hl.state,
                hl.county,
                hl.province,
                hl.postal_code,
                hl.country,
                hcsu.site_use_code,
                hcsu.status "Site Use Status",
                hcsu.primary_flag,
                hcsu.location,
                hcsu.bill_to_site_use_id "Bill to Location",
                rt.name "Payment Term",
                hcsu.attribute1 "Revenue Location",
                null as "Ship Method",
                rt.name "Payment Term",
                qlh.name,
                hl.address1 "Internal Location",              
                hl.address1 "Internal Organization",
                'HZ_CPUI' as "CREATED_BY_MODULE",
                fu.user_name
  FROM hz_parties hp,
       hz_party_sites hps,
       hz_locations hl,
       hz_cust_accounts_all hca,
       hz_cust_acct_sites_all hcsa,
       hz_cust_site_uses_all hcsu,
       hr_operating_units hou,
       ra_terms rt,
       qp_list_headers qlh,
       fnd_user fu
 WHERE     hp.party_id = hps.party_id
       AND hps.location_id = hl.location_id
       AND hp.party_id = hca.party_id
       AND hcsa.party_site_id = hps.party_site_id
       AND hcsu.cust_acct_site_id = hcsa.cust_acct_site_id
       AND hca.cust_account_id = hcsa.cust_account_id
       AND hou.organization_id = hcsa.org_id
       AND rt.term_id = hcsu.payment_term_id
       AND QLH.list_header_id = hcsu.price_list_id
       AND fu.user_id = hca.created_by
       AND hl.address1 LIKE 'US1%CLIN%FIS%'