title: Cannot set variable in if else statement in MySql
body: <p>I created a stored procedure which requirement as below</p>
  
  <p>When I execute the stored procedure with one username typed in which be compare if username are exists in database then (variable) result_userId will set at userId ELSE if username dose not exists in database then (variable) result_userId will be set the number 99</p>
  
  <p><em>BUT I CANNOT DO THAT</em> </p>
  
  <p>Please help me !</p>
  
  <p>::CODE BELOW::</p>
  
  <pre><code>DELIMITER $$
  USE `shoppy` $$
  CREATE PROCEDURE `testProc02`
  (
      IN  _username  CHAR(50),
      OUT result_userId   INT UNSIGNED
  )
  BEGIN
      SELECT @uId := userId FROM user 
      WHERE userName = _username;
      IF @uId = NULL THEN
          SET result_userId = 99;
      ELSE
          SET result_userId = @uId;
      END IF;    
  END $$
  DELIMITER ;
  </code></pre>
  
  <p>When I CALL testProc02();</p>
  
  <p><a href="https://i.stack.imgur.com/e5CaC.png" rel="nofollow noreferrer">enter image description here</a></p>