﻿UPDATE tanora
SET C_CSENGETESIRENDID = csro.C_CSENGETESIRENDID
FROM T_TANITASIORA tanora
INNER JOIN T_CSENGETESIRENDORA csro ON tanora.C_CSENGETESIRENDORAID = csro.ID
WHERE    tanora.C_MEGTARTOTT = 'F'
        AND tanora.C_CSENGETESIRENDORAID IS NOT NULL
        AND tanora.C_CSENGETESIRENDID IS NULL
        AND C_TANORANKIVULIFOGLALKOZAS = 'F'
        AND tanora.TOROLT = 'F'
GO

UPDATE 
T_TANITASIORA SET C_CSENGETESIRENDID = NULL
WHERE C_CSENGETESIRENDORAID IS NULL AND C_CSENGETESIRENDID IS NOT NULL
AND C_TANORANKIVULIFOGLALKOZAS = 'T'
GO

UPDATE nn
 SET nn.C_ORARENDINAP = tr.C_ORARENDINAP 
FROM T_NAPTARINAP nn
 INNER JOIN T_TANEVRENDJE tr ON nn.C_INTEZMENYID = tr.C_INTEZMENYID AND nn.C_TANEVID = tr.C_TANEVID AND nn.C_NAPDATUMA = tr.C_DATUM
WHERE nn.C_NAPDATUMA = '20180316'
 AND tr.C_OSSZESCSOPORTRAVONATKOZIK = 'T'
 AND tr.TOROLT = 'F'
 GO
