﻿update c
set TOROLT = 'T', MODIFIER = 0, LASTCHANGED = GETDATE(), SERIAL += 1
from T_CIM c
inner join 
  (
  select * from
    (
    select
       c.ID
      ,ROW_NUMBER() OVER(PARTITION BY c.C_CIMTIPUSA, c.C_TANEVID, c.C_FELHASZNALOID, c.C_GONDVISELOID ORDER BY c.C_ALAPERTELMEZETT desc, c.CREATED) as 'SorSzam'
    from T_CIM c
    inner join T_TANEV te on te.ID = c.C_TANEVID and te.TOROLT = 'F'
    where c.TOROLT = 'F'
    ) as SorSzamozott
  where SorSzamozott.SorSzam > 1
  ) as Torlendok
on Torlendok.ID = c.ID