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