title: sql scheduler to update balance leaves
body: <p>This is my credit leave table.</p>
  
  <pre><code>creditleaveid   empid   creditleavemonth    creditedleaves
  1               21      March                1
  </code></pre>
  
  <p>I am using scheduler to insert next month to credit/balance leave in this table is</p>
  
  <pre><code>DELIMITER $$
  CREATE EVENT creditleavemonth
  ON SCHEDULE EVERY '1' MONTH
  STARTS '2017-02-01 00:00:00'
  DO 
  BEGIN
   CALL spAddCreditLeaves;
  END$$
  
  DELIMITER ;
  </code></pre>
  
  <p>stored procedure spAddCreditLeaves is</p>
  
  <pre><code>DELIMITER $$
  
  USE `attendance`$$
  
  DROP PROCEDURE IF EXISTS `spAddCreditLeaves`$$
  
  CREATE DEFINER=`root`@`localhost` PROCEDURE `spAddCreditLeaves`()
  BEGIN
  INSERT INTO creditleaves(empid,creditleavemonth)SELECT empid,MONTHNAME(CURDATE())FROM empdetails;
  END$$
  
  DELIMITER ;
  </code></pre>
  
  <p>Now I want to update a record of inserted month by checking previous month's record for every employee. How to do that?</p>