In this query, if you are looking for customer account for a particular email address, uncomment condition on email and comment condition of phone. This is needed for performance purpose only. It would have been better if query could perform well for search across email and phone.
SELECT account_number
, 'Party LeveL ' || contact_point_type Communication_LeveL
, phne.contact_point_purpose
, phne.contact_point_type
, decode(phne.contact_point_type, 'PHONE','('||phne.phone_area_code ||') ' ||phne.phone_number,
'EMAIL', phne.email_address,
'WEB' , phne.url
) comm_detail
, phne.primary_flag
, null address
FROM apps.hz_contact_points phne
, apps.hz_cust_accounts acct
WHERE acct.party_id = phne.owner_table_id
AND phne.owner_table_name = 'HZ_PARTIES'
-- AND UPPER(phne.email_address) = 'EMAIL IN UPPER CASE'
AND phne.phone_area_code = '952' AND phne.phone_number = '0007353'
UNION
SELECT account_number
, 'Party Site LeveL ' || contact_point_type
, phne.contact_point_purpose
, phne.contact_point_type
, decode(phne.contact_point_type, 'PHONE','('||phne.phone_area_code ||') ' ||phne.phone_number,
'EMAIL', phne.email_address,
'WEB' , phne.url
) comm_detail
, phne.primary_flag
, loc.address1 || ',' ||loc.address2 || ',' ||loc.city || ',' ||loc.state || ',' ||loc.postal_code address
FROM apps.hz_contact_points phne
, apps.hz_cust_acct_sites_all site
, apps.hz_cust_accounts acct
, apps.hz_party_sites psite
, apps.hz_locations loc
WHERE site.cust_acct_site_id = phne.owner_table_id
AND phne.owner_table_name = 'HZ_PARTY_SITES'
AND site.cust_account_id = acct.cust_account_id
AND site.party_site_id = psite.party_site_id
AND psite.location_id = loc.location_id
-- AND UPPER(phne.email_address) = 'EMAIL IN UPPER CASE'
AND phne.phone_area_code = '952' AND phne.phone_number = '0007353'
No comments:
Post a Comment