DROP PROCEDURE  IF EXISTS uspGetGondviseloEmailCimEugyintezes 
GO

CREATE PROCEDURE uspGetGondviseloEmailCimEugyintezes
  @pId INT
AS
BEGIN
  SET NOCOUNT ON;

  SELECT e.C_EMAILCIM AS EmailCim
    ,IIF(e.C_ALAPERTELMEZETT = 'T', 1, 0) AS Alapertelmezett
    ,e.C_GUID AS Guid
  FROM T_GONDVISELO_OSSZES g
  INNER JOIN T_EMAIL_OSSZES e ON g.ID = e.C_GONDVISELOID
    AND e.TOROLT = 'F'
    AND e.C_ISHIBASANMEGADVA = 'F'
    AND e.C_ALAPERTELMEZETT = 'T'
  WHERE g.ID = @pId
    AND g.TOROLT = 'F'
  ORDER BY Alapertelmezett DESC
END
GO


