DROP FUNCTION IF EXISTS fnGetDokumentumIdegenNyelv
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION fnGetDokumentumIdegenNyelv (@nyomtatvanyNyelvEnum INT, @Id INT, @tanevId INT)
  RETURNS NVARCHAR(MAX)
BEGIN  
  DECLARE @value NVARCHAR(MAX)
  DECLARE @intezmenyId INT

  SELECT @intezmenyId = (SELECT C_INTEZMENYID FROM T_TANEV_OSSZES WHERE ID = @tanevId AND TOROLT= 'F')

  SELECT @value = (SELECT 
  CASE @nyomtatvanyNyelvEnum
  WHEN 0 THEN
    C_NAME
  WHEN 1 THEN
    C_NAME_2
  WHEN 2 THEN
    C_NAME_1
    END
  FROM T_DICTIONARYITEMBASE_OSSZES WHERE ID = @Id AND C_TANEVID = @tanevId AND C_INTEZMENYID = @intezmenyId AND TOROLT = 'F')

  RETURN @value  
END;