Translate

Saturday, August 20, 2016

Query to get Customer Information

SELECT party.party_type customer_type,
         party.party_name organization_name,
         acct.account_number,
         acct.account_name account_description,
         acct.customer_class_code classification,
         acct.sales_channel_code sales_channel,
         (SELECT meaning
            FROM fnd_lookup_values                                --ar_lookups
           WHERE     lookup_type = 'CUSTOMER_TYPE'
                 AND language = USERENV ('LANG')
                 AND lookup_code = acct.customer_type)
            account_type,
         (SELECT meaning
            FROM fnd_lookups
           WHERE lookup_type = 'OKL_CUSTOMER_STATUS'
                 AND lookup_code = acct.status)
            customer_status,
         (SELECT territory_short_name
            FROM fnd_territories_vl
           WHERE territory_code = hl.country)
            country,
         hl.address1 address_line_1,
         hl.city,
         hl.postal_code,
         (SELECT meaning
            FROM fnd_lookups
           WHERE lookup_type = 'OKL_CUSTOMER_STATUS'
                 AND lookup_code = hps.status)
            address_status,
         (SELECT hr.name
            FROM hr_all_organization_units hr
           WHERE hr.organization_id = hcsua.org_id)
            operating_unit,
         hcsa.customer_category_code category,
         (SELECT meaning
            FROM fnd_lookups
           WHERE lookup_type = 'ACCOUNT_STATUS' AND lookup_code = hcsa.status)
            acc_site_status,
         hcsua.location,
         hcsua.primary_flag primary,
         (SELECT concatenated_segments
            FROM gl_code_combinations_kfv glcc
           WHERE hcsua.gl_id_rec = glcc.code_combination_id)
            receivable_account,
         (SELECT concatenated_segments
            FROM gl_code_combinations_kfv glcc
           WHERE hcsua.gl_id_rev = glcc.code_combination_id)
            revenue_account,
         (SELECT t.name
            FROM ra_terms_vl t
           WHERE t.term_id = hcsua.payment_term_id)
            payment_terms,
         (SELECT resource_name
            FROM jtf_rs_salesreps jrs,
                 jtf_rs_resource_extns b,
                 jtf_rs_resource_extns_tl t
           WHERE     jrs.resource_id = b.resource_id
                 AND t.language = USERENV ('LANG')
                 AND b.resource_id = t.resource_id
                 AND b.category = t.category
                 AND b.category IN
                        ('EMPLOYEE',
                         'OTHER',
                         'PARTY',
                         'PARTNER',
                         'SUPPLIER_CONTACT')
                 AND jrs.salesrep_id = hcsua.primary_salesrep_id
                 AND jrs.org_id = hcsua.org_id)
            salesperson,
         (SELECT t.name
            FROM oe_transaction_types_tl t, oe_transaction_types_syn b
           WHERE     b.transaction_type_id(+) = t.transaction_type_id
                 AND t.language = USERENV ('LANG')
                 AND t.transaction_type_id = hcsua.order_type_id)
            order_type,
         (SELECT name
            FROM qp_list_headers_tl t, qp_list_headers_b b
           WHERE     b.list_header_id(+) = t.list_header_id
                 AND t.language = USERENV ('LANG')
                 AND t.list_header_id = hcsua.price_list_id)
            price_list,
         (SELECT t.name
            FROM ra_terms_vl t, hz_cust_site_uses_all hcsua1
           WHERE     t.term_id = hcsua1.payment_term_id
                 AND hcsua1.cust_acct_site_id = hcsa.cust_acct_site_id
                 AND hcsua1.site_use_id = hcsua.site_use_id
                 AND hcsua1.site_use_code = 'SHIP_TO')
            ship_payment_terms,
         (SELECT resource_name
            FROM jtf_rs_salesreps jrs,
                 jtf_rs_resource_extns b,
                 jtf_rs_resource_extns_tl t,
                 hz_cust_site_uses_all hcsua1
           WHERE     jrs.resource_id = b.resource_id
                 AND t.language = USERENV ('LANG')
                 AND b.resource_id = t.resource_id
                 AND b.category = t.category
                 AND b.category IN
                        ('EMPLOYEE',
                         'OTHER',
                         'PARTY',
                         'PARTNER',
                         'SUPPLIER_CONTACT')
                 AND jrs.salesrep_id = hcsua1.primary_salesrep_id
                 AND hcsua1.cust_acct_site_id = hcsa.cust_acct_site_id
                 AND hcsua1.site_use_id = hcsua.site_use_id
                 AND hcsua1.site_use_code = 'SHIP_TO')
            ship_salesperson,
         (SELECT t.name
            FROM oe_transaction_types_tl t,
                 oe_transaction_types_syn b,
                 hz_cust_site_uses_all hcsua1
           WHERE     b.transaction_type_id(+) = t.transaction_type_id
                 AND t.language = USERENV ('LANG')
                 AND hcsua1.site_use_code = 'SHIP_TO'
                 AND t.transaction_type_id = hcsua1.order_type_id
                 AND hcsua1.site_use_id = hcsua.site_use_id
                 AND hcsua1.cust_acct_site_id = hcsa.cust_acct_site_id)
            ship_order_type,
         (SELECT name
            FROM qp_list_headers_tl t,
                 qp_list_headers_b b,
                 hz_cust_site_uses_all hcsua1
           WHERE     b.list_header_id(+) = t.list_header_id
                 AND t.language = USERENV ('LANG')
                 AND t.list_header_id = hcsua1.price_list_id
                 AND hcsua1.site_use_id = hcsua.site_use_id
                 AND hcsua1.site_use_code = 'SHIP_TO'
                 AND hcsua1.cust_acct_site_id = hcsa.cust_acct_site_id)
            ship_price_list,
         (SELECT hcpc.name
            FROM hz_cust_profile_classes hcpc
           WHERE hcpc.profile_class_id = profile.profile_class_id)
            profile_class,
         (SELECT ac.name
            FROM ar_collectors ac
           WHERE ac.collector_id = profile.collector_id)
            collector,
         profile.credit_classification,
         profile.credit_checking,
         profile.credit_hold,
         profile.percent_collectable,
         profile.standard_terms,
         profile.override_terms,
         profile.discount_terms allow_discount,
         profile.discount_grace_days,
         profile.auto_rec_incl_disputed_flag,
         profile.send_statements,
         profile.credit_balance_statements send_credit_balance,
         (SELECT ast.name
            FROM ar_statement_cycles ast
           WHERE ast.statement_cycle_id = profile.statement_cycle_id)
            statement_cycle,
         profile.dunning_letters,
         profile.tax_printing_option,
         (SELECT rgr.name
            FROM ra_grouping_rules rgr
           WHERE rgr.grouping_rule_id = profile.grouping_rule_id)
            grouping_rule,
         hcpa.currency_code profile_currency,
         hcpa.overall_credit_limit credit_limit,
         hcpa.trx_credit_limit order_credit_limit,
         DECODE (profile.late_charge_calculation_trx,
                 'LATE', profile.late_charge_calculation_trx)
            late_payments_only,
         DECODE (profile.late_charge_calculation_trx,
                 'OVERDUE', profile.late_charge_calculation_trx)
            overdue_invoices_only,
         DECODE (profile.late_charge_calculation_trx,
                 'OVERDUE_LATE', profile.late_charge_calculation_trx)
            overdue_invoices_late_payments,
         (SELECT t.name
            FROM fnd_currencies_tl t, fnd_currencies b
           WHERE     b.currency_code = t.currency_code
                 AND t.language = USERENV ('LANG')
                 AND t.currency_code = hcpa.currency_code)
            late_chrg_currency
    FROM hz_cust_accounts acct,
         hz_parties party,
         hz_customer_profiles profile,
         hz_party_sites hps,
         hz_cust_site_uses_all hcsua,
         hz_cust_acct_sites_all hcsa,
         hz_locations hl,
         hz_cust_profile_amts hcpa
   WHERE     1 = 1
         AND hcsua.site_use_code = 'BILL_TO'
         AND acct.party_id = party.party_id
         AND profile.party_id = party.party_id
         AND acct.cust_account_id = profile.cust_account_id
         AND profile.site_use_id = hcsua.site_use_id
         AND hps.party_id = party.party_id
         AND hcsa.cust_acct_site_id = hcsua.cust_acct_site_id
         AND hcsa.cust_account_id = acct.cust_account_id
         AND hcsa.party_site_id = hps.party_site_id
         AND hps.location_id = hl.location_id
         AND hcpa.cust_account_id = profile.cust_account_id
         AND hcpa.cust_account_profile_id = profile.cust_account_profile_id
         AND hcpa.site_use_id IS NOT NULL
         AND hcpa.site_use_id = profile.site_use_id
ORDER BY acct.account_number

No comments:

Post a Comment

Featured Post

To Add user Responsibility like another user

DECLARE    lc_user_name              VARCHAR2 (100) := 'ALI';    lc_resp_appl_short_name   VARCHAR2 (100) := 'SYSADMIN'; ...