title: How to set 2 calculated output parameters in select statement
body: <p>I'm creating a stored procedure in SQL Server 2016 where basically I'm going to validate user &amp; password combination to know if the user is valid, if so I want to set two OUTPUT parameters, one containing a Boolean value that means the user is valid (because later in my app I want to check that bool value) and the other one containing the ID of the user.</p>
  
  <p>My SPROC looks like this</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[uspLogin]
  (
      @Email AS VARCHAR(200),
      @Password AS VARCHAR(200),
      @IsValid AS BIT OUTPUT,
      @UserId AS INT OUTPUT
  )
  AS
  BEGIN
  
      SET NOCOUNT ON;
  
      BEGIN TRY
  
  
          BEGIN TRANSACTION;
  
          SELECT 
          @IsValid = (CASE WHEN COUNT(*) &gt; 0 THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END),
          @UserId = (CASE WHEN COUNT(*) &gt; 0 THEN CAST(U.UserId AS INT) ELSE CAST(-1 AS INT) END)
          FROM [dbo].[User] AS U
          INNER JOIN [dbo].[UserEnabled] AS UE ON U.UserId = UE.UserId
          WHERE U.Email = @Email AND U.Password = @Password
  
          COMMIT TRANSACTION;
  
      END TRY
      BEGIN CATCH
  
          IF @@TRANCOUNT &gt; 0
              ROLLBACK TRANSACTION;
  
          DECLARE @ErrorMessage nvarchar(4000) = 'Error: [' + ERROR_MESSAGE() + '] in line [' + CAST(ERROR_LINE() AS varchar(1000)) + '] of procedure [' + ERROR_PROCEDURE() + ']';
  
          RAISERROR(@Errormessage, 18, 0);
  
      END CATCH;
  
  END
  </code></pre>
  
  <p>Once executed I'm getting this error:</p>
  
  <blockquote>
    <p>Column 'dbo.User.UserId' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.</p>
  </blockquote>