﻿DECLARE @sql nvarchar(max) = ''
SELECT @sql += N'
  EXEC dbo.sp_Global_GenerateTanevAdatokFromExistingTanev ' + CAST(i.ID AS nvarchar(20)) + N', ''2017/2018'', ''2016/2017'', 1;'  
FROM T_INTEZMENY i
WHERE NOT EXISTS (SELECT 1 FROM T_TANEV t WHERE t.C_INTEZMENYID = i.ID AND t.C_NEV = '2017/2018' AND t.TOROLT = 'F')
  AND i.TOROLT = 'F'
  
EXEC sp_executesql @sql
