DROP PROCEDURE IF EXISTS uspGetIsElmaradtOraAndPedagogusHasNemkotottMunkaido
GO

CREATE PROCEDURE uspGetIsElmaradtOraAndPedagogusHasNemkotottMunkaido
   @pTanitasioraId int  
AS BEGIN
  SET NOCOUNT ON;

  DECLARE @HasUtkozes bit = 0 
  SET @HasUtkozes = ISNULL((SELECT TOP 1 1 FROM T_TANITASIORA_OSSZES tao
          INNER JOIN T_NEMKOTOTTMUNKAIDO_OSSZES nkm ON ISNULL(tao.C_HELYETTESITOTANARID, tao.C_TANARID) = nkm.C_TANARID AND nkm.TOROLT = 'F'
      WHERE
        tao.ID = @pTanitasioraId
        AND tao.C_MEGTARTOTT = 'F' 
        AND (tao.C_ORAKEZDETE BETWEEN nkm.C_KEZDETE AND nkm.C_VEGE OR nkm.C_KEZDETE BETWEEN tao.C_ORAKEZDETE AND tao.C_ORAVEGE)
  ), 0)

  SELECT @HasUtkozes AS HasUtkozes
END