SELECT DISTINCT 0 , A.LM_CI_ID , ( SELECT MAX(X.LM_ROW_MAINT_DTTM) FROM PS_LM_ACT X WHERE X.LM_CI_ID = A.LM_CI_ID ) AS LM_ROW_MAINT_DTTM FROM PS_LM_CI_TBL A, PS_LM_CI_SEC_TBL B WHERE A.LM_CI_ID = B.LM_CI_ID AND %CurrentDateIn BETWEEN A.EFFDT AND A.LM_END_EFFDT AND B.EFFDT = A.EFFDT AND EXISTS ( SELECT COUNT(*) FROM PS_LM_CI_SEC_TBL SEC1 WHERE SEC1.LM_CI_ID = A.LM_CI_ID AND SEC1.EFFDT = A.EFFDT GROUP BY SEC1.LM_CI_ID HAVING COUNT(*) = ( SELECT COUNT (DISTINCT A2.LM_LRNR_GROUP_ID ) FROM PS_LM_ACT A3 , PS_LM_ACT_SEC A2 WHERE A3.LM_CI_ID = A.LM_CI_ID AND A3.LM_ACT_ID = A2.LM_ACT_ID AND A3.LM_START_DT <= %CurrentDateIn AND ( A3.LM_END_DT >= %CurrentDateIn OR A3.LM_END_DT IS NULL) AND A3.LM_ACT_STATUS = '1' GROUP BY A3.LM_CI_ID ) )
|