﻿DROP PROCEDURE IF EXISTS uspKIRstat_Evfolyam
GO

CREATE PROCEDURE uspKIRstat_Evfolyam
   @pFeladatellatasiHelyId int
  ,@pTanevId int
AS
BEGIN
  SET NOCOUNT ON;

  SELECT DISTINCT 
    d.C_NAME_4
    ,CASE d.C_NAME_4 
      WHEN 'Kis' THEN -3
      WHEN 'Középső' THEN -2
      WHEN 'Nagy' THEN -1
      WHEN 'Na' THEN 100
      ELSE ISNULL(TRY_CAST(d.C_NAME_4 AS int), 100) 
    END AS Sort
  FROM T_OSZTALYCSOPORT_OSSZES ocs 
    INNER JOIN T_OSZTALY_OSSZES o ON o.ID = ocs.ID AND o.C_ALTANEVID = ocs.C_TANEVID AND o.TOROLT = 'F'
    INNER JOIN T_DICTIONARYITEMBASE_OSSZES d ON d.ID = ocs.C_EVFOLYAMTIPUSA AND d.C_TANEVID = ocs.C_TANEVID AND d.TOROLT = 'F'
  WHERE ocs.C_FELADATELLATASIHELYID = @pFeladatEllatasiHelyId 
    AND C_NAME_4 IS NOT NULL
    AND LEN(C_NAME_4) > 0
    AND ocs.C_TANEVID = @pTanevid 
    AND ocs.TOROLT = 'F'
  ORDER BY Sort

END

GO

