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