title: MySQL Stored Procedure with IF/THEN/ELSE
body: <p>I have a MySQL stored procedure and in it, the following WHILE statement.</p>
  
  <p>I have confirmed that @RowCnt is 1, and @MaxRows is 6090, however after further debugging, I realized that the WHILE statement is going through a single iteration and not continuing; so I'm hoping to have some light shed on what could possibly be causing this.</p>
  
  <p>Full disclosure: I ported this from SQL Server to a MySQL stored procedure, something I have never taken on before. (meaning SQL Server, porting OR stored procedures..)</p>
  
  <pre><code>WHILE @RowCnt &lt;= @MaxRows DO
      SELECT @currentReadSeq:=ReadSeq, @currentReadStrength:=ReadStrength, @currentReadDateTime:=ReadDateTime, @currentReaderID:=ReaderID FROM tblTempRead WHERE rownum = @RowCnt;
  
      IF ( ((@lastReadSeq + 10) &gt; @currentReadSeq) AND (@lastReaderId = @currentReaderId) ) THEN 
          SET @lastReadSeq = @currentReadSeq, @lastReadStrength = @currentReadStrength, @lastReadDateTime = @currentReadDateTime, @lastReaderID = @currentReaderID;
      ELSE
          INSERT INTO tblreaddataresults (SiteID, ReadDateTimeStart, ReadDateTimeEnd, ReadSeqStart, ReadSeqEnd, ReaderID, DirectSeconds) VALUES ('1002', @saveReadDateTime, @lastReadDateTime, @saveReadSeq, @lastReadSeq, @lastReaderID, timestampdiff(SECOND,@saveReadDateTime,@lastReadDateTime));
  
          SET @saveReadSeq = @currentReadSeq, @saveReadStrength = @currentReadStrength, @saveReadDateTime = @currentReadDateTime, @saveReaderID = @currentReaderID;
  
          SET @lastReadSeq = @saveReadSeq, @lastReadStrength = @saveReadStrength, @lastReadDateTime = @saveReadDateTime, @lastReaderID = @saveReaderID;
      END IF;
  
      SET @RowCnt = @RowCnt+1;
  END WHILE;
  </code></pre>