/* Formatted on 9/11/2014 3:52:27 PM (QP5 v5.115.810.9015) */
SELECT app.approval_group_id
FROM hz_cust_site_uses_all use,
hz_cust_acct_sites_all sit,
hz_customer_profiles prf,
laaf_approval_groups app
WHERE 1 = 1
AND use.site_use_id = #disposition_id1#
AND use.cust_acct_site_id = sit.cust_acct_site_id
/* Manually Added Code */
AND sit.cust_account_id = prf.cust_account_id(+)
AND NVL (prf.site_use_id, -999) = -999
AND 'SM_BILL_TO_' || TO_CHAR (use.org_id) || '_' || prf.collector_id =
app.approval_group
UNION
SELECT app.approval_group_id
FROM hz_cust_site_uses_all use, laaf_approval_groups app
WHERE 1 = 1
AND use.site_use_id = #disposition_id1#
AND 'SM_BILL_TO_' || TO_CHAR(use.org_id) = app.approval_group
AND NOT EXISTS
(SELECT *
FROM hz_cust_site_uses_all t_use,
laaf_approval_groups t_app,
hz_cust_acct_sites_all t_sit,
hz_customer_profiles t_prf
WHERE 1 = 1
AND t_use.site_use_id = #disposition_id1#
AND t_use.cust_acct_site_id = t_sit.cust_acct_site_id
AND t_sit.cust_account_id = t_prf.cust_account_id(+)
AND NVL (t_prf.site_use_id, -999) = -999
AND 'SM_BILL_TO_'
|| TO_CHAR (t_use.org_id)
|| '_'
|| t_prf.collector_id = t_app.approval_group)
UNION
SELECT app.approval_group_id
FROM laaf_approval_groups app
WHERE 1 = 1 AND app.approval_group = 'No Approver'
AND NOT EXISTS
(SELECT *
FROM hz_cust_site_uses_all use, laaf_approval_groups app
WHERE 1 = 1 AND use.site_use_id = #disposition_id1#
AND 'SM_BILL_TO_' || TO_CHAR(use.org_id) =
app.approval_group)
AND NOT EXISTS
(SELECT *
FROM hz_cust_site_uses_all t_use,
laaf_approval_groups t_app,
hz_cust_acct_sites_all t_sit,
hz_customer_profiles t_prf
WHERE 1 = 1
AND t_use.site_use_id = #disposition_id1#
AND t_use.cust_acct_site_id = t_sit.cust_acct_site_id
AND t_sit.cust_account_id = t_prf.cust_account_id(+)
AND NVL (t_prf.site_use_id, -999) = -999
AND 'SM_BILL_TO_'
|| TO_CHAR (t_use.org_id)
|| '_'
|| t_prf.collector_id = t_app.approval_group)
select * from laaf_approval_groups
SELECT app.approval_group_id
FROM hz_cust_site_uses_all use,
hz_cust_acct_sites_all sit,
hz_customer_profiles prf,
laaf_approval_groups app
WHERE 1 = 1
AND use.site_use_id = #disposition_id1#
AND use.cust_acct_site_id = sit.cust_acct_site_id
/* Manually Added Code */
AND sit.cust_account_id = prf.cust_account_id(+)
AND NVL (prf.site_use_id, -999) = -999
AND 'SM_BILL_TO_' || TO_CHAR (use.org_id) || '_' || prf.collector_id =
app.approval_group
UNION
SELECT app.approval_group_id
FROM hz_cust_site_uses_all use, laaf_approval_groups app
WHERE 1 = 1
AND use.site_use_id = #disposition_id1#
AND 'SM_BILL_TO_' || TO_CHAR(use.org_id) = app.approval_group
AND NOT EXISTS
(SELECT *
FROM hz_cust_site_uses_all t_use,
laaf_approval_groups t_app,
hz_cust_acct_sites_all t_sit,
hz_customer_profiles t_prf
WHERE 1 = 1
AND t_use.site_use_id = #disposition_id1#
AND t_use.cust_acct_site_id = t_sit.cust_acct_site_id
AND t_sit.cust_account_id = t_prf.cust_account_id(+)
AND NVL (t_prf.site_use_id, -999) = -999
AND 'SM_BILL_TO_'
|| TO_CHAR (t_use.org_id)
|| '_'
|| t_prf.collector_id = t_app.approval_group)
UNION
SELECT app.approval_group_id
FROM laaf_approval_groups app
WHERE 1 = 1 AND app.approval_group = 'No Approver'
AND NOT EXISTS
(SELECT *
FROM hz_cust_site_uses_all use, laaf_approval_groups app
WHERE 1 = 1 AND use.site_use_id = #disposition_id1#
AND 'SM_BILL_TO_' || TO_CHAR(use.org_id) =
app.approval_group)
AND NOT EXISTS
(SELECT *
FROM hz_cust_site_uses_all t_use,
laaf_approval_groups t_app,
hz_cust_acct_sites_all t_sit,
hz_customer_profiles t_prf
WHERE 1 = 1
AND t_use.site_use_id = #disposition_id1#
AND t_use.cust_acct_site_id = t_sit.cust_acct_site_id
AND t_sit.cust_account_id = t_prf.cust_account_id(+)
AND NVL (t_prf.site_use_id, -999) = -999
AND 'SM_BILL_TO_'
|| TO_CHAR (t_use.org_id)
|| '_'
|| t_prf.collector_id = t_app.approval_group)
select * from laaf_approval_groups
No comments:
Post a Comment