title: get app users role, name for the valid users login using stored procedure
body: <p>I've made stored procedure which is used to validate user login and get the role and name of the valid user. I've some confusions, please make me clear.</p>
  
  <ol>
  <li>is this the optimized way to do this?</li>
  <li>what is I use IF EXISTS (SELECT 1) to check for username and password and if returns true then only get the role and name of the valid user  </li>
  <li>@v_out_login_message returns 0, why ?</li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>create procedure p_user_login
  (
   @user_name     varchar(20),
   @password     varchar(10), 
   @v_out_role    char output,
   @v_out_name    varchar(50) output,
   @v_out_login_message  int = 0 output
  )
  as
  begin
   select @v_out_role = role, @v_out_name = name from user_information
    where user_name = @user_name and password = @password and status = 1;
   if @@rowcount = 0 
    set @v_out_login_message = 1 -- user can login
   else set @v_out_login_message = 0 -- invalid login
  end</code></pre>
  </div>
  </div>
  </p>
  
  <blockquote>
    <p>declare @v_out_role   char, @v_out_name varchar(50),
    @v_out_login_message int</p>
    
    <p>exec p_user_login 'admin','admin', @v_out_role output, @v_out_name
    output, @v_out_login_message output</p>
    
    <p>select  @v_out_role as role, @v_out_name as name, @v_out_login_message
    as login_message</p>
  </blockquote>
  
  <p>@v_out_login_message is returning 0 why? </p>