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