SELECT C1.LM_CI_ID , ERL.LM_ENRLMT_ID , ACT.LM_ACT_ID FROM PS_LM_CI_TBL C1 , PS_LM_ACT ACT , PS_LM_ENRLMT ERL WHERE C1.EFFDT = ( SELECT MAX(Y1.EFFDT) FROM PS_LM_CI_TBL Y1 WHERE C1.LM_CI_ID = Y1.LM_CI_ID AND Y1.EFFDT <= %CurrentDateIn) AND C1.LM_CI_ID=ERL.LM_CI_ID AND ERL.LM_ACT_ID = ACT.LM_ACT_ID UNION SELECT C1.LM_CI_ID , ERL.LM_ENRLMT_ID , 0 FROM PS_LM_CI_TBL C1 , PS_LM_ENRLMT ERL WHERE C1.EFFDT = ( SELECT MAX(Y1.EFFDT) FROM PS_LM_CI_TBL Y1 WHERE C1.LM_CI_ID = Y1.LM_CI_ID AND Y1.EFFDT <= %CurrentDateIn) AND C1.LM_CI_ID=ERL.LM_CI_ID AND ERL.LM_STTS= 'WAIV'
|