SELECT DISTINCT a.case_id , b.relationship_type , CASE WHEN(a.case_id = b.case_id AND c.hierarchical_ind = 'Y') THEN ( SELECT DISTINCT %Upper(parent_lbl) FROM ps_rc_relation_tbl d WHERE c.relationship_type = d.relationship_type AND d.setid = ( SELECT setid FROM ps_SET_CNTRL_TBL WHERE setcntrlvalue = a.business_unit) AND d.parent_lbl <> ' ') WHEN(a.case_id = b.related_case_id AND c.hierarchical_ind = 'Y') THEN ( SELECT DISTINCT %Upper(child_lbl) FROM ps_rc_relation_tbl e WHERE c.relationship_type = e.relationship_type AND e.setid = ( SELECT setid FROM ps_SET_CNTRL_TBL WHERE setcntrlvalue = a.business_unit) AND e.child_lbl <> ' ') WHEN(a.case_id = b.case_id AND c.hierarchical_ind = 'N') THEN ( SELECT DISTINCT %Upper(equivalent_lbl) FROM ps_rc_relation_tbl f WHERE c.relationship_type = f.relationship_type AND f.setid = ( SELECT setid FROM ps_SET_CNTRL_TBL WHERE setcntrlvalue = a.business_unit) AND f.equivalent_lbl <> ' ') WHEN(a.case_id = b.related_case_id AND c.hierarchical_ind = 'N') THEN ( SELECT DISTINCT %Upper(equivalent_lbl) FROM ps_rc_relation_tbl g WHERE c.relationship_type = g.relationship_type AND g.setid = ( SELECT setid FROM ps_SET_CNTRL_TBL WHERE setcntrlvalue = a.business_unit) AND g.equivalent_lbl <> ' ') END, a.syncid, %DateTimeOut(a.syncdttm) FROM ps_rc_case a, PS_RC_RELATIONSHIP b, ps_rc_relation_tbl c WHERE(a.case_id = b.case_id OR a.case_id = b.related_case_id) AND b.relationship_type = c.relationship_type
|