SELECT DISTINCT H.SHEET_ID , H.CREATION_DT , H.SUBMISSION_DATE , U.OPRID FROM PS_EX_SHEET_HDR H , PS_EX_SHEET_AW X , PS_EOAW_STEPINST S , PS_EOAW_USERINST U WHERE H.SHEET_ID = X.SHEET_ID AND X.EOAWTHREAD_ID = S.EOAWTHREAD_ID AND X.EOAWPRCS_ID = S.EOAWPRCS_ID AND X.EOAWDEFN_ID = S.EOAWDEFN_ID AND S.EOAWSTEP_INSTANCE = U.EOAWSTEP_INSTANCE AND X.EOAWTHREAD_ID = ( CASE WHEN EXISTS ( SELECT EOAWTHREAD_STATUS FROM PS_EX_SHEET_AW C1 WHERE H.SHEET_ID = C1.SHEET_ID AND C1.RECNAME = 'EX_ER_HDR_AW_VW' AND C1.EOAWTHREAD_STATUS = 'P') THEN ( SELECT MIN(X1.EOAWTHREAD_ID) FROM PS_EX_SHEET_AW X1 WHERE X1.SHEET_ID = X.SHEET_ID) WHEN EXISTS ( SELECT EOAWTHREAD_STATUS FROM PS_EX_SHEET_AW C1 WHERE H.SHEET_ID = C1.SHEET_ID AND C1.RECNAME = 'EX_ER_LN_AW_VW' AND C1.EOAWTHREAD_STATUS = 'P') THEN ( SELECT MAX(X1.EOAWTHREAD_ID) FROM PS_EX_SHEET_AW X1 WHERE X1.SHEET_ID = X.SHEET_ID) END )
|