SELECT DISTINCT C.SETID , C.CUST_ID , MA.SUPPORT_TEAM_MBR , MA.NAME1 FROM ps_customer C , PS_CUST_TEAM CT , PS_TEAM_MEMBERS TM , PS_MEMBER_PERSON MA WHERE c.cust_status = 'A' AND c.bill_to_flg = 'Y' AND c.cust_level <> 'P' AND CT.SETID = C.SETID AND CT.CUST_ID = C.CUST_ID AND CT.DEFAULT_FLAG = 'Y' AND TM.SETID = ( SELECT TS.SETID FROM PS_SET_CNTRL_REC TS WHERE TS.RECNAME = 'TEAM_MEMBERS' AND TS.SETCNTRLVALUE = C.SETID) AND TM.SUPPORT_TEAM_CD = CT.SUPPORT_TEAM_CD AND TM.EFFDT = ( SELECT MAX(TC.EFFDT) FROM PS_TEAM_CODE_TBL TC WHERE TC.SETID = TM.SETID AND TC.SUPPORT_TEAM_CD = TM.SUPPORT_TEAM_CD AND TC.EFF_STATUS = 'A' AND TC.EFFDT <= %CurrentDateIn) AND TM.PRIORITY = ( SELECT MIN(TY.PRIORITY) FROM PS_TEAM_MEMBERS TY WHERE TY.SETID = TM.SETID AND TY.SUPPORT_TEAM_CD = TM.SUPPORT_TEAM_CD AND TY.EFFDT = TM.EFFDT AND TY.PRIORITY > 0) AND MA.SETID = TM.SETID AND MA.SUPPORT_TEAM_MBR = TM.SUPPORT_TEAM_MBR AND MA.EFF_STATUS = 'A'
|