SELECT DISTINCT D.OPRID , A.SCC_TM_LIST_ID , A.SCC_TM_LABEL , A.PORTAL_NAME ,A.SCC_TM_PARENT_TMPL , ITML.SCC_TM_DUE_DATE , A.LAST_UPDATE_DTTM , %DateDiff(%currentdatein,ITML.SCC_TM_DUE_DATE ) FROM PS_SCC_TM_PTAILIST A , PS_SCC_TM_CONFIG B , PSOPRDEFN D , PS_SCC_TM_PTAIITEM ITML , PS_SCC_TM_PTAIITEM ITMF WHERE A.SCC_TM_PARENT_TMPL = B.SCC_TM_TASK_ID AND A.SCC_TM_ACTIVE_FLAG = 'Y' AND A.SCC_TM_IS_TMPL='N' AND A.SCC_TM_LIST_STATUS = 'IP' AND A.SCC_TM_LIST_ID = ITML.SCC_TM_LIST_ID AND ITML.SCC_TM_PTAI_SEQ = ( SELECT MAX(ITM1.SCC_TM_PTAI_SEQ) FROM PS_SCC_TM_PTAIITEM ITM1 WHERE A.SCC_TM_LIST_ID = ITM1.SCC_TM_LIST_ID ) AND A.SCC_TM_LIST_ID = ITMF.SCC_TM_LIST_ID AND ITMF.SCC_TM_PTAI_SEQ = ( SELECT MIN(ITM2.SCC_TM_PTAI_SEQ) FROM PS_SCC_TM_PTAIITEM ITM2 WHERE A.SCC_TM_LIST_ID = ITM2.SCC_TM_LIST_ID ) AND %Coalesce(ITMF.SCC_TM_START_DATE,%CurrentDateIn) <= %CurrentDateIn
|