﻿DECLARE @Id int, @tanevId int, @intezmenyId int

DECLARE fb_cursor CURSOR FOR   
SELECT ID, C_INTEZMENYID, C_TANEVID
   FROM T_FELHASZNALO_OSSZES
   WHERE C_TANEVID IN (
	   SELECT ID
	   FROM T_TANEV_OSSZES
	   WHERE C_NEV = '2017/2018')
     AND C_UTONEV = 'Adminisztrátor'

OPEN fb_cursor  

FETCH NEXT FROM fb_cursor   
INTO @Id, @intezmenyId, @tanevId

WHILE @@FETCH_STATUS = 0  
BEGIN  

    UPDATE T_FELHASZNALOBELEPES_OSSZES
	  SET C_FELHASZNALOID = @Id
	WHERE C_TANEVID = @tanevId
		AND C_INTEZMENYID = @intezmenyId
		AND C_BEJELENTKEZESINEV = 'admin'

    FETCH NEXT FROM fb_cursor   
    INTO @Id, @intezmenyId, @tanevId
END   
CLOSE fb_cursor;  
DEALLOCATE fb_cursor;  
GO
