﻿DECLARE @datum DATETIME = '20181231'

INSERT INTO T_LICENCE
(C_DATE, C_FULL, C_FUNCTION, C_INTEZMENYID, C_TANEVID)
SELECT  @datum, 'T', NULL, tv.C_INTEZMENYID, tv.ID
FROM T_INTEZMENY i
INNER JOIN T_TANEV tv ON tv.C_INTEZMENYID = i.ID
WHERE i.TOROLT = 'F'
AND 0 = (SELECT COUNT(1) FROM T_LICENCE licence WHERE licence.C_TANEVID = tv.ID AND licence.C_INTEZMENYID = i.ID)
