DROP PROCEDURE IF EXISTS uspGetAdminEmail
GO
  CREATE PROCEDURE uspGetAdminEmail
    @pIntezmenyAzonosito NVARCHAR(30)
  AS
  BEGIN
    SET NOCOUNT ON;

    SELECT COALESCE(ia.C_ADMINEMAILCIM, ia.C_EMAILCIM) AS Email
    FROM T_INTEZMENYADATOK_OSSZES ia
    INNER JOIN T_INTEZMENY_OSSZES i ON i.ID = ia.C_INTEZMENYID
      AND i.TOROLT = 'F'
      AND i.C_AZONOSITO = @pIntezmenyAzonosito
    INNER JOIN T_TANEV_OSSZES t ON t.ID = ia.C_TANEVID
      AND t.TOROLT = 'F'
      AND t.C_AKTIV = 'T'
      AND t.C_INTEZMENYID = i.ID
    WHERE ia.TOROLT = 'F'
  END
GO


