Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
24 views5 pages

Customer Detail Information

The document contains a SQL query that retrieves customer account information, including billing and shipping locations, party details, and account statuses from various tables in a database. It uses multiple subqueries to extract specific site use IDs and addresses for billing and shipping, along with party and account information such as organization name, account number, and credit limits. The query is structured to ensure distinct results and includes various conditions for filtering the data.

Uploaded by

Furqan Salam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views5 pages

Customer Detail Information

The document contains a SQL query that retrieves customer account information, including billing and shipping locations, party details, and account statuses from various tables in a database. It uses multiple subqueries to extract specific site use IDs and addresses for billing and shipping, along with party and account information such as organization name, account number, and credit limits. The query is structured to ensure distinct results and includes various conditions for filtering the data.

Uploaded by

Furqan Salam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

SELECT distinct hcas.

cust_account_id customer_id ,

(select distinct HCSU1.SITE_USE_ID FROM


HZ_CUST_SITE_USES_ALL HCSU1,
HZ_LOCATIONS HL1,
hz_cust_acct_sites_ALL HCAS1,
-- hz_party_sites HPS,
hz_parties hp1
WHERE
1=1
and
HCSU1.Cust_Acct_Site_Id = hcas1.cust_acct_site_id
AND HCSU1.SITE_USE_CODE
= 'BILL_TO'
and HCSU1.PRIMARY_FLAG
= 'Y'
AND HCAS1.party_site_id
= HPS.party_site_id
and HL1.location_id =
HPS.location_id
AND HCAS1.ORG_ID
=HCAS.ORG_ID
and hp1.party_id
= hps.party_id ) bil_to_loc_id,

(select distinct HL1.ADDRESS1 FROM


HZ_CUST_SITE_USES_ALL HCSU1,
HZ_LOCATIONS HL1,
hz_cust_acct_sites_ALL HCAS1,
-- hz_party_sites HPS,
hz_parties hp1
WHERE
1=1
and
HCSU1.Cust_Acct_Site_Id = hcas1.cust_acct_site_id
AND HCSU1.SITE_USE_CODE
= 'BILL_TO'
and HCSU1.PRIMARY_FLAG
= 'Y'
AND HCAS1.party_site_id
= HPS.party_site_id
and HL1.location_id =
HPS.location_id
AND HCAS1.ORG_ID
=HCAS.ORG_ID
and hp1.party_id
= hps.party_id ) bil_to_loc_Name,

(select distinct HCSU2.SITE_USE_ID FROM


HZ_CUST_SITE_USES_ALL HCSU2,
HZ_LOCATIONS HL2,
hz_cust_acct_sites_ALL HCAS2,
-- hz_party_sites HPS,
hz_parties hp2
WHERE
1=1
and
HCSU2.Cust_Acct_Site_Id = hcas2.cust_acct_site_id
AND HCSU2.SITE_USE_CODE
= 'SHIP_TO'
AND HCAS2.party_site_id
= HPS.party_site_id
and HL2.location_id =
HPS.location_id
and HCSU2.PRIMARY_FLAG
= 'Y'
AND HCAS2.ORG_ID
=HCAS.ORG_ID
and hp2.party_id
= hps.party_id ) ship_to_loc_id,

(select distinct HL2.ADDRESS1 FROM


HZ_CUST_SITE_USES_ALL HCSU2,
HZ_LOCATIONS HL2,
hz_cust_acct_sites_ALL HCAS2,
-- hz_party_sites HPS,
hz_parties hp2
WHERE
1=1
and
HCSU2.Cust_Acct_Site_Id = hcas2.cust_acct_site_id
AND HCSU2.SITE_USE_CODE
= 'SHIP_TO'
AND HCAS2.party_site_id
= HPS.party_site_id
and HL2.location_id =
HPS.location_id
and HCSU2.PRIMARY_FLAG
= 'Y'
AND HCAS2.ORG_ID
=HCAS.ORG_ID
and hp2.party_id
= hps.party_id ) ship_to_loc_Name,

----------------------------------------------------------
-- Party Information
----------------------------------------------------------
haou.name org_name,
hp.party_number oracle_party_no,
hp.attribute1 Cust_legacy_no,
hp.party_name "Party Name",
hp.party_type "Party Type",
hp.tax_reference VAT_NUMBER,
hp.jgzz_fiscal_code TIN_NO,
/* DECODE(hp.status,
'A', 'Active',
'I', 'Inactive',
hp.status) "Party Status",
*/ ----------------------------------------------------------
-- Account Information
----------------------------------------------------------
hca.account_number "Account Number",
DECODE(hca.status,
'A', 'Active',
'I', 'Inactive',
hca.status) "Account Status",
hca.account_name "Account Description",
hca.customer_class_code "Classification",
DECODE(hca.customer_type,
'R', 'External',
'I', 'Internal',
hca.customer_type) "Account Type",
----------------------------------------------------------
-- Site Information
----------------------------------------------------------
/*hps.party_site_number "Customer Site Number",
DECODE(hcas.status,
'A', 'Active',
'Inactive') "Site Status",
DECODE(hcas.bill_to_flag,
'P', 'Primary',
'Y', 'Yes',
hcas.bill_to_flag) "Bill To Flag",
DECODE(hcas.ship_to_flag,
'P', 'Primary',
'Y', 'Yes',
hcas.ship_to_flag) "Ship To Flag",
hcas.cust_acct_site_id "Customer Acct Site ID",*/
----------------------------------------------------------
-- Address Information
----------------------------------------------------------
hl.address1 Billing_address,
hl.address2 Address,
hl.city "City",
hl.state "Province/State",
hl.postal_code "postal Code",
hl.country country,
-- ter.name "sales_Territory",
----------------------------------------------------------
-- Account Profile Information
---------------------------------------------------------
(select hcpc.name from HZ_CUST_PROFILE_CLASSES hcpc where
hcpc.profile_class_id = hcp.profile_class_id) Profile_class,
--hcp.credit_checking "Credit Check Flag",
--hcp.credit_hold "Credit Hold Flag",
--hcpa.auto_rec_min_receipt_amount "Min Receipt Amount",
hcpa.overall_credit_limit PROFILE_AMOUNT,
hp_per.title designation_of_contact_person,
hp_per.person_name name_of_contact_person,
hp_per.person_phone phone_no_of_contact_person

--hcpa.trx_credit_limit "Order Credit Limit",


----------------------------------------------------------
-- Attachment Flag
----------------------------------------------------------
/* NVL((SELECT 'Y'
FROM fnd_documents_vl doc,
fnd_lobs blo,
fnd_attached_documents att
WHERE doc.media_id = blo.file_id
AND doc.document_id = att.document_id
AND att.entity_name = 'AR_CUSTOMERS'
AND att.pk1_value = hca.cust_account_id
AND ROWNUM = 1), 'N'
) "Attachment Flag",
----------------------------------------------------------
-- Party Relationship Flag
----------------------------------------------------------
NVL((SELECT 'Y'
FROM hz_cust_acct_relate_all hzcar
WHERE hzcar.cust_account_id = hca.cust_account_id
AND hzcar.relationship_type = 'ALL'
AND ROWNUM = 1), 'N'
) "Party Relationship Flag",
----------------------------------------------------------
-- Account Relationship Flag
----------------------------------------------------------
NVL((SELECT 'Y'
FROM hz_cust_acct_relate_all hzcar
WHERE hzcar.cust_account_id = hca.cust_account_id
AND ROWNUM = 1), 'N'
) "Account Relationship Flag",
----------------------------------------------------------
-- Party Contact Flag
----------------------------------------------------------
----------------------------------------------------------
-- Account Contact Flag
----------------------------------------------------------
/* NVL((SELECT 'Y'
FROM hz_contact_points
WHERE status = 'A'
AND owner_table_id =
(SELECT hcar.party_id
FROM hz_cust_account_roles hcar,
ar_contacts_v acv
WHERE hcar.cust_account_id = hca.cust_account_id
AND hcar.cust_account_role_id = acv.contact_id
AND hcar.cust_acct_site_id IS NULL -- look for account
level only
AND ROWNUM = 1 -- add this row to show inactive sites (i.e.
with no site id)
)
AND ROWNUM = 1), 'N'
) "Account Contact Flag",
----------------------------------------------------------
-- Site Contact Flag
----------------------------------------------------------
*/
FROM
-- ar_customers ac,
hz_parties hp,
hz_party_sites hps,
hz_cust_accounts_all hca,
hz_cust_acct_sites_all hcas,
--hz_cust_site_uses_all hcsua,
hz_customer_profiles hcp,
hz_cust_profile_amts hcpa,
hz_locations hl,
-- ra_territories ter,
-- ar_collectors col,
hr_all_organization_units haou,
(sELECT DISTINCT cust_account_id,HPP.PERSON_TITLE TITLE,
HPP.PERSON_FIRST_NAME||' '||HPP.PERSON_MIDDLE_NAME||' '||
HPP.PERSON_LAST_NAME PERSON_NAME,
REL_HP.PRIMARY_PHONE_COUNTRY_CODE||'-'||
REL_HP.PRIMARY_PHONE_AREA_CODE||'-'||REL_HP.PRIMARY_PHONE_NUMBER PERSON_PHONE
FROM hz_parties hp,
hz_parties rel_hp,
hz_person_profiles hpp,
hz_relationships hr,
hz_org_contacts hoc,
hz_contact_points hcp,
hz_cust_account_roles hcar
WHERE hoc.party_relationship_id = hr.relationship_id
and hcp.owner_table_id = hcar.party_id
AND hr.subject_id = hp.party_id
AND rel_hp.party_id = hr.party_id
AND hp.party_id = hpp.party_id(+)
AND hpp.content_source_type(+) = 'USER_ENTERED'
AND hpp.effective_end_date IS NULL
AND rel_hp.party_id = hcar.party_id(+)
AND hoc.party_relationship_id = hr.relationship_id
AND hr.subject_table_name = 'HZ_PARTIES'
AND hr.subject_type = 'PERSON'
AND hr.relationship_code = 'CONTACT_OF'
--AND hcar.cust_account_id = 1041
AND hcar.cust_acct_site_id is null)HP_PER

WHERE
1=1
AND hp.party_id = hca.party_id
AND hca.cust_account_id = hcas.cust_account_id(+)
AND hps.party_site_id(+) = hcas.party_site_id
AND hp.party_id = hcp.party_id
AND hca.cust_account_id = hcp.cust_account_id
AND hps.location_id = hl.location_id(+)
--AND col.collector_id = hcp.collector_id
-- AND hcas.territory_id = ter.territory_id(+)
AND hcp.cust_account_profile_id = hcpa.cust_account_profile_id(+)
and haou.organization_id = hcas.org_id
and hcas.cust_account_id = hp_per.cust_account_id(+)

-- and hoc.party_relationship_id = hr.relationship_id(+)


-- and

----
-- AND hp.party_type = 'ORGANIZATION' -- only ORGANIZATION Party
types
-- AND hp.status = 'A' -- only Active
Parties/Customers
----
-- following conditions are for testing purpose only
-- comment/uncomment as needed
----
-- AND hp.party_number = 1146
--and hp.party_name ='Pranto Traders'
-- AND hca.account_number = 32253 --32396 --31753 --32253 --31038
ORDER BY TO_NUMBER(hp.party_number), hp.party_name, hca.account_number

You might also like