SELECT B.VC_PLAN_ID , B.VC_PAYOUT_PRD_ID , C.EFFDT , A.TREE_NAME , A.EFFDT , B.PRD_END_DT FROM PS_VC_TREE_DT_VW A , PS_VC_PAYPRD_TBL B , PS_VC_PLAN_EFFDT C WHERE B.VC_PLAN_ID = C.VC_PLAN_ID AND C.TREE_NAME = A.TREE_NAME AND A.EFFDT = ( SELECT MAX(VC_TREE_DT_VW.EFFDT) FROM PS_VC_TREE_DT_VW VC_TREE_DT_VW WHERE VC_TREE_DT_VW.TREE_NAME = A.TREE_NAME AND VC_TREE_DT_VW.EFFDT <= B.PRD_END_DT AND VC_TREE_DT_VW.EFFDT <= %CurrentDateIn) AND C.EFFDT = ( SELECT MAX(EFFDT) FROM PS_VC_PLAN_EFFDT VC_PLAN_EFFDT WHERE B.VC_PLAN_ID = VC_PLAN_EFFDT.VC_PLAN_ID AND VC_PLAN_EFFDT.EFFDT <= %CurrentDateIn AND VC_PLAN_EFFDT.EFFDT <= B.PRD_END_DT) AND C.EFF_STATUS = 'A'
|