SELECT A.SETID ,A.AUDIT_STATUS ,A.LANGUAGE_CD ,A.INSTANCE_NAME FROM PS_RE_AUDIT_STS_LG A WHERE A.EFFDT = ( SELECT MAX(B.EFFDT) FROM PS_RE_AUDIT_STS_LG B WHERE A.SETID = B.SETID AND A.AUDIT_STATUS = B.AUDIT_STATUS AND B.EFFDT <= %CurrentDateIn ) OR (A.EFFDT = ( SELECT MIN(C.EFFDT) FROM PS_RE_AUDIT_STS_LG C WHERE C.SETID = A.SETID AND C.AUDIT_STATUS = A.AUDIT_STATUS AND C.EFFDT > %CurrentDateIn) AND NOT EXISTS ( SELECT 1 FROM PS_RE_AUDIT_STS_LG D WHERE D.SETID = A.SETID AND D.AUDIT_STATUS = A.AUDIT_STATUS AND D.EFFDT = ( SELECT MAX(E.EFFDT) FROM PS_RE_AUDIT_STS_LG E WHERE D.SETID = E.SETID AND D.AUDIT_STATUS = E.AUDIT_STATUS AND E.EFFDT <= %CurrentDateIn )))
|