title: Check multiple conditions in Stored Procedure on SQL Server 2008
body: <p><strong>Following my stored procedure</strong></p>
  
  <pre><code>ALTER PROCEDURE [dbo].[Proc_userlogin] @userid   VARCHAR(50),
                                         @password VARCHAR(50)
  AS
      DECLARE @ReturnVal VARCHAR(500)
  
      SET nocount ON
  
      IF EXISTS(SELECT username,
                       password
                FROM   clients
                WHERE  username = @userid
                       AND password = Hashbytes('SHA1', @password))
        SET @ReturnVal='0|Logged in Successfully'
      ELSE IF NOT EXISTS(SELECT username
                    FROM   clients
                    WHERE  username = @userid)
        SET @ReturnVal='1|Incorrect Username'
      ELSE IF NOT EXISTS(SELECT username,
                           password
                    FROM   clients
                    WHERE  username = @userid
                           AND password = Hashbytes('SHA1', @password))
        SET @ReturnVal='1|Incorrect Password'
  
      SELECT @ReturnVal  
  </code></pre>
  
  <p>In above Stored Procedure I am checking whether the username and password has been entered correctly.The issue that I was facing was checking multiple conditions.Can multiple select queries be eliminated and single select query in the If condition be used to check authentication?.Can the above Stored Procedure be customized to minimize the number of select statements within if conditions.</p>
  
  <p>Please suggest</p>
  
  <p>Thanks</p>