and ccb.bp_category in ('TENANT','GUARANTOR') and (ccb.id_card_no = ${@id_no} or ccb.id_no_sp = ${@id_no})))
or (${@account_type} = 'AG' and exists (select 1 from hls_bp_master_signer hs where hs.hls_bp_signer_id = t1.signer and hs.id_card = ${@id_no}))
or (${@account_type} = 'AG' and exists (select 1 from con_contract_bp cb where cb.contract_id = t1.contract_id and cb.bp_category = 'GUARANTOR' and cb.bp_class = 'ORG' and cb.id_card_no_leg = ${@id_no}))
or (${@account_type} = 'LP' and exists
(select 1
from con_contract_bp cb, hls_bp_master hb
where cb.bp_id = hb.bp_id
and cb.contract_id = t1.contract_id
and hb.social_code = ${@id_no}))
)
UNION ALL
select t1.contract_id,
...
...
@@ -162,6 +168,12 @@ select *
and ccb.bp_category in ('TENANT','GUARANTOR') and (ccb.id_card_no = ${@id_no} or ccb.id_no_sp = ${@id_no})))
or (${@account_type} = 'AG' and exists (select 1 from hls_bp_master_signer hs where hs.hls_bp_signer_id = t1.signer and hs.id_card = ${@id_no}))
or (${@account_type} = 'AG' and exists (select 1 from con_contract_bp cb where cb.contract_id = t1.contract_id and cb.bp_category = 'GUARANTOR' and cb.bp_class = 'ORG' and cb.id_card_no_leg = ${@id_no}))