﻿-- =============================================
-- Description:	Beszúrjuk a paraméterül kapott táblába a 
-- többi paraméternek megfelelően az üres sorokat, hogy az 
-- frx meg tudja jeleníteni az üres táblázatokat is.
-- =============================================
DROP PROCEDURE IF EXISTS [dbo].[uspInsertMunkaidoElszamoloLapUresSorokUresTablazatokhoz]
GO

CREATE PROCEDURE [dbo].[uspInsertMunkaidoElszamoloLapUresSorokUresTablazatokhoz]
   @pTableName nvarchar(255)
	,@pFelnottkepzesKulon int
	,@pElmeletGyakorlatKulon int
  ,@pTanarId int
  ,@pHonap int
  ,@pBontas int
AS
BEGIN

	SET NOCOUNT ON;
	
  DECLARE @sql nvarchar(max)

  SET @sql = N'
  IF @pFelnottkepzesKulon = 0 
    AND @pElmeletGyakorlatKulon = 0 
    AND NOT EXISTS (SELECT pedagogusId FROM ' + @pTableName + N' WHERE IsFelnottoktatas = ''F'' AND IsGyakorlat = ''-'') BEGIN
    INSERT INTO ' + @pTableName + N' (pedagogusId, OsztalyCsoportID, OsztalyCsoportNev, Honap
      ,[1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
      [11], [12], [13], [14], [15], [16], [17], [18], [19], [20],
      [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]
      ,Ossz ,IsFelnottoktatas, IsGyakorlat
      ,[1b], [2b], [3b], [4b], [5b], [6b], [7b], [8b], [9b], [10b],
      [11b], [12b], [13b], [14b], [15b], [16b], [17b], [18b], [19b], [20b],
      [21b], [22b], [23b], [24b], [25b], [26b], [27b], [28b], [29b], [30b], [31b])
    VALUES (@pTanarId, -1, '''', @pHonap
      ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
      ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
      ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
      ,0, ''F'', ''-''
      ,CASE @pBontas
        WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 1) = ''T'', 0, 1)
        WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 1) = ''T'', 0, 1)
        WHEN 2 THEN 0
        END
      ,CASE @pBontas
        WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 2) = ''T'', 0, 1)
        WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 2) = ''T'', 0, 1)
        WHEN 2 THEN 0
        END
      ,CASE @pBontas
        WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 3) = ''T'', 0, 1)
        WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 3) = ''T'', 0, 1)
        WHEN 2 THEN 0
        END
      ,CASE @pBontas
        WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 4) = ''T'', 0, 1)
        WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 4) = ''T'', 0, 1)
        WHEN 2 THEN 0
        END
      ,CASE @pBontas
        WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 5) = ''T'', 0, 1)
        WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 5) = ''T'', 0, 1)
        WHEN 2 THEN 0
        END
      ,CASE @pBontas
        WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 6) = ''T'', 0, 1)
        WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 6) = ''T'', 0, 1)
        WHEN 2 THEN 0
        END
      ,CASE @pBontas
        WHEN 2 THEN 0
        ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 7) = ''T'', 0, 1)
        END
      ,CASE @pBontas
        WHEN 2 THEN 0
        ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 8) = ''T'', 0, 1)
        END
      ,CASE @pBontas
        WHEN 2 THEN 0
        ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 9) = ''T'', 0, 1)
        END
      ,CASE @pBontas
        WHEN 2 THEN 0
        ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 10) = ''T'', 0, 1)
        END
      ,CASE @pBontas
        WHEN 2 THEN 0
        ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 11) = ''T'', 0, 1)
        END
      ,CASE @pBontas
        WHEN 2 THEN 0
        ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 12) = ''T'', 0, 1)
        END
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 13) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 14) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 15) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 16) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 17) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 18) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 19) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 20) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 21) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 22) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 23) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 24) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 25) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 26) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 27) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 28) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 29) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 30) = ''T'', 0, 1)
      ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 31) = ''T'', 0, 1)
    )
  END
  IF @pFelnottkepzesKulon = 1 
    AND @pElmeletGyakorlatKulon = 0 BEGIN
      IF NOT EXISTS (SELECT pedagogusId FROM ' + @pTableName + N' WHERE IsFelnottoktatas = ''T'' AND IsGyakorlat = ''-'') BEGIN
        INSERT INTO ' + @pTableName + N' (pedagogusId, OsztalyCsoportID, OsztalyCsoportNev, Honap
          ,[1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
          [11], [12], [13], [14], [15], [16], [17], [18], [19], [20],
          [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]
          ,Ossz ,IsFelnottoktatas, IsGyakorlat
          ,[1b], [2b], [3b], [4b], [5b], [6b], [7b], [8b], [9b], [10b],
          [11b], [12b], [13b], [14b], [15b], [16b], [17b], [18b], [19b], [20b],
          [21b], [22b], [23b], [24b], [25b], [26b], [27b], [28b], [29b], [30b], [31b])
        VALUES (@pTanarId, -1, '''', @pHonap
          ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
          ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
          ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
          ,0, ''T'', ''-''
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 1) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 1) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 2) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 2) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 3) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 3) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 4) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 4) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 5) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 5) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 6) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 6) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 7) = ''T'', 0, 1)
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 8) = ''T'', 0, 1)
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 9) = ''T'', 0, 1)
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 10) = ''T'', 0, 1)
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 11) = ''T'', 0, 1)
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 12) = ''T'', 0, 1)
            END
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 13) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 14) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 15) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 16) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 17) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 18) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 19) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 20) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 21) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 22) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 23) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 24) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 25) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 26) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 27) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 28) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 29) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 30) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 31) = ''T'', 0, 1)
        )
      END
      IF NOT EXISTS (SELECT pedagogusId FROM ' + @pTableName + N' WHERE IsFelnottoktatas = ''F'' AND IsGyakorlat = ''-'') BEGIN
        INSERT INTO ' + @pTableName + N' (pedagogusId, OsztalyCsoportID, OsztalyCsoportNev, Honap
          ,[1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
          [11], [12], [13], [14], [15], [16], [17], [18], [19], [20],
          [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]
          ,Ossz ,IsFelnottoktatas, IsGyakorlat
          ,[1b], [2b], [3b], [4b], [5b], [6b], [7b], [8b], [9b], [10b],
          [11b], [12b], [13b], [14b], [15b], [16b], [17b], [18b], [19b], [20b],
          [21b], [22b], [23b], [24b], [25b], [26b], [27b], [28b], [29b], [30b], [31b])
        VALUES (@pTanarId, -1, '''', @pHonap
          ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
          ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
          ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
          ,0, ''F'', ''-''
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 1) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 1) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 2) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 2) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 3) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 3) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 4) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 4) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 5) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 5) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 6) = ''T'', 0, 1)
            WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 6) = ''T'', 0, 1)
            WHEN 2 THEN 0
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 7) = ''T'', 0, 1)
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 8) = ''T'', 0, 1)
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 9) = ''T'', 0, 1)
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 10) = ''T'', 0, 1)
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 11) = ''T'', 0, 1)
            END
          ,CASE @pBontas
            WHEN 2 THEN 0
            ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 12) = ''T'', 0, 1)
            END
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 13) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 14) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 15) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 16) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 17) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 18) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 19) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 20) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 21) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 22) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 23) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 24) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 25) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 26) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 27) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 28) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 29) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 30) = ''T'', 0, 1)
          ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 31) = ''T'', 0, 1)
        )
      END
  END
  IF @pFelnottkepzesKulon = 0 
    AND @pElmeletGyakorlatKulon = 1 BEGIN
    IF NOT EXISTS (SELECT pedagogusId FROM ' + @pTableName + N' WHERE IsFelnottoktatas = ''F'' AND IsGyakorlat = ''T'') BEGIN
      INSERT INTO ' + @pTableName + N' (pedagogusId, OsztalyCsoportID, OsztalyCsoportNev, Honap
        ,[1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
        [11], [12], [13], [14], [15], [16], [17], [18], [19], [20],
        [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]
        ,Ossz ,IsFelnottoktatas, IsGyakorlat
        ,[1b], [2b], [3b], [4b], [5b], [6b], [7b], [8b], [9b], [10b],
        [11b], [12b], [13b], [14b], [15b], [16b], [17b], [18b], [19b], [20b],
        [21b], [22b], [23b], [24b], [25b], [26b], [27b], [28b], [29b], [30b], [31b])
      VALUES (@pTanarId, -1, '''', @pHonap
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,0, ''F'', ''T''
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 1) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 1) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 2) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 2) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 3) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 3) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 4) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 4) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 5) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 5) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 6) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 6) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 7) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 8) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 9) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 10) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 11) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 12) = ''T'', 0, 1)
          END
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 13) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 14) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 15) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 16) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 17) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 18) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 19) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 20) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 21) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 22) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 23) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 24) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 25) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 26) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 27) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 28) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 29) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 30) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 31) = ''T'', 0, 1)
      )
    END
    IF NOT EXISTS (SELECT pedagogusId FROM ' + @pTableName + N' WHERE IsFelnottoktatas = ''F'' AND IsGyakorlat = ''F'') BEGIN
      INSERT INTO ' + @pTableName + N' (pedagogusId, OsztalyCsoportID, OsztalyCsoportNev, Honap
        ,[1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
        [11], [12], [13], [14], [15], [16], [17], [18], [19], [20],
        [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]
        ,Ossz ,IsFelnottoktatas, IsGyakorlat
        ,[1b], [2b], [3b], [4b], [5b], [6b], [7b], [8b], [9b], [10b],
        [11b], [12b], [13b], [14b], [15b], [16b], [17b], [18b], [19b], [20b],
        [21b], [22b], [23b], [24b], [25b], [26b], [27b], [28b], [29b], [30b], [31b])
      VALUES (@pTanarId, -1, '''', @pHonap
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,0, ''F'', ''F''
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 1) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 1) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 2) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 2) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 3) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 3) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 4) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 4) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 5) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 5) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 6) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 6) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 7) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 8) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 9) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 10) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 11) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 12) = ''T'', 0, 1)
          END
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 13) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 14) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 15) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 16) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 17) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 18) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 19) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 20) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 21) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 22) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 23) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 24) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 25) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 26) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 27) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 28) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 29) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 30) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 31) = ''T'', 0, 1)
      )
    END
  END
  IF @pFelnottkepzesKulon = 1 
    AND @pElmeletGyakorlatKulon = 1 BEGIN
    IF NOT EXISTS (SELECT pedagogusId FROM ' + @pTableName + N' WHERE IsFelnottoktatas = ''T'' AND IsGyakorlat = ''T'') BEGIN
      INSERT INTO ' + @pTableName + N' (pedagogusId, OsztalyCsoportID, OsztalyCsoportNev, Honap
        ,[1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
        [11], [12], [13], [14], [15], [16], [17], [18], [19], [20],
        [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]
        ,Ossz ,IsFelnottoktatas, IsGyakorlat
        ,[1b], [2b], [3b], [4b], [5b], [6b], [7b], [8b], [9b], [10b],
        [11b], [12b], [13b], [14b], [15b], [16b], [17b], [18b], [19b], [20b],
        [21b], [22b], [23b], [24b], [25b], [26b], [27b], [28b], [29b], [30b], [31b])
      VALUES (@pTanarId, -1, '''', @pHonap
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,0, ''T'', ''T''
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 1) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 1) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 2) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 2) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 3) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 3) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 4) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 4) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 5) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 5) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 6) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 6) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 7) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 8) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 9) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 10) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 11) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 12) = ''T'', 0, 1)
          END
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 13) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 14) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 15) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 16) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 17) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 18) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 19) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 20) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 21) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 22) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 23) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 24) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 25) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 26) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 27) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 28) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 29) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 30) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 31) = ''T'', 0, 1)
      )
    END
    IF NOT EXISTS (SELECT pedagogusId FROM ' + @pTableName + N' WHERE IsFelnottoktatas = ''T'' AND IsGyakorlat = ''F'') BEGIN
      INSERT INTO ' + @pTableName + N' (pedagogusId, OsztalyCsoportID, OsztalyCsoportNev, Honap
        ,[1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
        [11], [12], [13], [14], [15], [16], [17], [18], [19], [20],
        [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]
        ,Ossz ,IsFelnottoktatas, IsGyakorlat
        ,[1b], [2b], [3b], [4b], [5b], [6b], [7b], [8b], [9b], [10b],
        [11b], [12b], [13b], [14b], [15b], [16b], [17b], [18b], [19b], [20b],
        [21b], [22b], [23b], [24b], [25b], [26b], [27b], [28b], [29b], [30b], [31b])
      VALUES (@pTanarId, -1, '''', @pHonap
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,0, ''T'', ''F''
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 1) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 1) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 2) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 2) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 3) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 3) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 4) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 4) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 5) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 5) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 6) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 6) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 7) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 8) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 9) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 10) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 11) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 12) = ''T'', 0, 1)
          END
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 13) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 14) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 15) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 16) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 17) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 18) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 19) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 20) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 21) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 22) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 23) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 24) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 25) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 26) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 27) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 28) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 29) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 30) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 31) = ''T'', 0, 1)
      )
    END
    IF NOT EXISTS (SELECT pedagogusId FROM ' + @pTableName + N' WHERE IsFelnottoktatas = ''F'' AND IsGyakorlat = ''T'') BEGIN
      INSERT INTO ' + @pTableName + N' (pedagogusId, OsztalyCsoportID, OsztalyCsoportNev, Honap
        ,[1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
        [11], [12], [13], [14], [15], [16], [17], [18], [19], [20],
        [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]
        ,Ossz ,IsFelnottoktatas, IsGyakorlat
        ,[1b], [2b], [3b], [4b], [5b], [6b], [7b], [8b], [9b], [10b],
        [11b], [12b], [13b], [14b], [15b], [16b], [17b], [18b], [19b], [20b],
        [21b], [22b], [23b], [24b], [25b], [26b], [27b], [28b], [29b], [30b], [31b])
      VALUES (@pTanarId, -1, '''', @pHonap
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,0, ''F'', ''T''
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 1) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 1) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 2) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 2) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 3) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 3) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 4) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 4) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 5) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 5) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 6) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 6) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 7) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 8) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 9) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 10) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 11) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 12) = ''T'', 0, 1)
          END
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 13) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 14) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 15) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 16) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 17) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 18) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 19) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 20) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 21) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 22) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 23) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 24) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 25) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 26) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 27) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 28) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 29) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 30) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 31) = ''T'', 0, 1)
      )
    END
    IF NOT EXISTS (SELECT pedagogusId FROM ' + @pTableName + N' WHERE IsFelnottoktatas = ''F'' AND IsGyakorlat = ''F'') BEGIN
      INSERT INTO ' + @pTableName + N' (pedagogusId, OsztalyCsoportID, OsztalyCsoportNev, Honap
        ,[1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
        [11], [12], [13], [14], [15], [16], [17], [18], [19], [20],
        [21], [22], [23], [24], [25], [26], [27], [28], [29], [30], [31]
        ,Ossz ,IsFelnottoktatas, IsGyakorlat
        ,[1b], [2b], [3b], [4b], [5b], [6b], [7b], [8b], [9b], [10b],
        [11b], [12b], [13b], [14b], [15b], [16b], [17b], [18b], [19b], [20b],
        [21b], [22b], [23b], [24b], [25b], [26b], [27b], [28b], [29b], [30b], [31b])
      VALUES (@pTanarId, -1, '''', @pHonap
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL
        ,0, ''F'', ''F''
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 1) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 1) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 2) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 2) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 3) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 3) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 4) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 4) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 5) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 5) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 0 THEN IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 6) = ''T'', 0, 1)
          WHEN 1 THEN IIF((SELECT h.IsTanitasiHet FROM #Hetek h WHERE h.Sorszam = 6) = ''T'', 0, 1)
          WHEN 2 THEN 0
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 7) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 8) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 9) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 10) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 11) = ''T'', 0, 1)
          END
        ,CASE @pBontas
          WHEN 2 THEN 0
          ELSE IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 12) = ''T'', 0, 1)
          END
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 13) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 14) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 15) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 16) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 17) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 18) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 19) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 20) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 21) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 22) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 23) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 24) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 25) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 26) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 27) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 28) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 29) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 30) = ''T'', 0, 1)
        ,IIF((SELECT tnt.IsTanitasiNap FROM #TanitasiNapTabla tnt WHERE tnt.Nap = 31) = ''T'', 0, 1)
      )
    END
  END
  '

  EXEC sp_executesql @sql
    ,N'@pFelnottkepzesKulon int
	  ,@pElmeletGyakorlatKulon int
    ,@pTanarId int
    ,@pHonap int
    ,@pBontas int'
	  ,@pFelnottkepzesKulon  = @pFelnottkepzesKulon
	  ,@pElmeletGyakorlatKulon = @pElmeletGyakorlatKulon
    ,@pTanarId = @pTanarId
    ,@pHonap = @pHonap
    ,@pBontas = @pBontas
END


GO

