title: While condition in my sql
body: <p>I have a sp to run recursively based on while condition . But while condition is not working as expected.</p>
  
  <pre><code>BEGIN
  declare moduleid VARCHAR(3);
  declare parent VARCHAR(3);
  declare flag int DEFAULT 0;
  
  SET max_sp_recursion_depth = 3;
  set moduleid = mdlid;
  set parent   = '';
  set flag     = 0;
  
  select moduleid;
  
  set parent = (
      select
          ms.parentModule as parentModule
      from
          x ms
      where
          ms.moduleid = moduleid
  );
  
  select parent;
  
  set flag = if( 'MNU' = parent, 0, 1 );
  
  select flag;
  
  while (flag &lt;&gt; 0) DO
  
      select
          ms.menuname
      from
          x ms
      where
          ms.moduleId = parent;
  
      select 'called recursive';
  
      call usp_testwhile(parent);
  
  end WHILE;
  
  END
  </code></pre>
  
  <p>though the flag value is 0 the statement inside while is executing.</p>
  
  <p>The original intention of this sp is to stop when the parentmenu is MNU.
  For eg the table structure of x is as follows,</p>
  
  <pre><code>moduleid    parentmodule  menuname
  aaa         bbb           alpha1
  bbb         ccc           alpha2
  ccc         MNU           alpha3
  </code></pre>
  
  <p>Expected functionality is 
  call spname('aaa');</p>
  
  <p>Now module id is aaa and parent is bbb. In while i'm checking parent !='MNU' condition fails and cycle 2 begins </p>
  
  <p>Now module id is bbb and parent is ccc. In while i'm checking parent !='MNU' condition fails and cycle 3 begins</p>
  
  <p>Now module id is ccc and parent is MNU. In while i'm checking parent !='MNU' condition satisfy and should stop executing .</p>