﻿--Migration
UPDATE v
SET TOROLT = 'T'
   ,MODIFIER = 0
   ,LASTCHANGED = GETDATE()
   ,SERIAL += 1
   FROM T_VEGZETTSEG_OSSZES v
   INNER JOIN (SELECT ID, ELOZOTANEVIREKORDID, ROW_NUMBER() OVER (
      PARTITION BY ELOZOTANEVIREKORDID, C_TANEVID
      ORDER BY created desc
   ) row_num FROM T_VEGZETTSEG_OSSZES 
WHERE ELOZOTANEVIREKORDID IS NOT NULL AND TOROLT = 'F') as v_r on v_r.ELOZOTANEVIREKORDID = v.ELOZOTANEVIREKORDID AND v_r.ID = v.ID
where v_r.row_num>1