﻿UPDATE oo
SET oo.C_CSENGETESIRENDORAID = x.csroId
FROM T_ORARENDIORA oo
INNER JOIN (
  SELECT TOP(3000) o.id AS ooId, cs.ID AS csroId
  FROM T_ORARENDIORA o
  INNER JOIN T_CSENGETESIRENDORA cs ON cs.C_ORASZAM = o.C_ORASZAM AND cs.C_CSENGETESIRENDID = o.C_CSENGETESIRENDID AND cs.TOROLT = 'F'
  WHERE o.C_CSENGETESIRENDORAID <> cs.ID
) x ON oo.ID = x.ooId

WHILE @@ROWCOUNT <> 0 BEGIN
  UPDATE oo
  SET oo.C_CSENGETESIRENDORAID = x.csroId
  FROM T_ORARENDIORA oo
  INNER JOIN (
	SELECT TOP(3000) o.id AS ooId, cs.ID AS csroId
	FROM T_ORARENDIORA o
	INNER JOIN T_CSENGETESIRENDORA cs ON cs.C_ORASZAM = o.C_ORASZAM AND cs.C_CSENGETESIRENDID = o.C_CSENGETESIRENDID AND cs.TOROLT = 'F'
	WHERE o.C_CSENGETESIRENDORAID <> cs.ID
  ) x ON oo.ID = x.ooId
END;
GO