SELECT
TO_DATE(CT.DOG_DATE, 'dd.mm.rrrr') DOG_DATE,
case when ct.dog_date>='01.01.2013' then cl.iin
else nvl(cl.iin,cl.rnn) end rnn,
UPPER(TRIM(CL.CLIENT_NAME)) CLI_NAME
FROM
CONTRACTS CT,
CLIENT CL
WHERE
CT.CLIENT = CL.CLIENT
AND CL.CLIENT_CATEGORY = 1
and rownum < 500 group by rnn;