SELECT i.SETID , p.BO_ID , ln.AGREEMENT_CODE , ln.AGR_RENEWAL_NUM , ln.AGREEMENT_LINE , i.INST_PROD_ID , i.ASSETTAG , i.DESCR FROM %Table(RC_INST_PROD_VW) i , %Table(RF_AGREEMENT_LN) ln , %Table(SET_CNTRL_REC) sc , %Table(RD_PERSON) p , %Table(RB_WORKER) w WHERE i.INST_PROD_TYPE = '001' AND p.PERSON_ID = w.PERSON_ID AND (i.BO_ID_CONTACT = p.BO_ID OR (i.DEPTID = w.DEPTID AND w.SETID_DEPT = ( SELECT sc2.SETID FROM %Table(SET_CNTRL_REC) sc2 WHERE sc2.SETCNTRLVALUE = i.SETID AND sc2.RECNAME = 'DEPT_TBL'))) AND ln.SETID = sc.SETID AND sc.SETCNTRLVALUE = i.SETID AND sc.RECNAME = 'RF_AGREEMENT_LN' AND ((i.PRODUCT_ID IN ( SELECT lnp.PRODUCT_ID FROM %Table(RF_AG_LINE_PROD) lnp WHERE lnp.SETID = ln.SETID AND lnp.AGREEMENT_CODE = ln.AGREEMENT_CODE AND lnp.AGR_RENEWAL_NUM = ln.AGR_RENEWAL_NUM AND lnp.AGREEMENT_LINE = ln.AGREEMENT_LINE AND lnp.PRODUCT_ID NOT IN ( SELECT i2.PRODUCT_ID FROM %Table(RF_INST_PROD) i2 , %Table(RF_UNDER_SVC) lni2 WHERE i2.SETID = i.SETID AND lni2.INST_PROD_ID = i2.INST_PROD_ID AND lni2.SETID = ln.SETID AND lni2.AGREEMENT_CODE = ln.AGREEMENT_CODE AND lni2.AGR_RENEWAL_NUM = ln.AGR_RENEWAL_NUM AND lni2.AGREEMENT_LINE = ln.AGREEMENT_LINE))) OR (i.INST_PROD_ID IN ( SELECT lni.INST_PROD_ID FROM %Table(RF_UNDER_SVC) lni WHERE lni.SETID = ln.SETID AND lni.AGREEMENT_CODE = ln.AGREEMENT_CODE AND lni.AGR_RENEWAL_NUM = ln.AGR_RENEWAL_NUM AND lni.AGREEMENT_LINE = ln.AGREEMENT_LINE)))
|