Created
May 26, 2022 03:33
-
-
Save raihan-uddin/d512d321d430ba502ee281bd855f6c72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELIMITER $$ | |
CREATE EVENT employeeResign | |
ON SCHEDULE EVERY 2 MINUTE | |
DO | |
BEGIN | |
DECLARE done INT DEFAULT FALSE; | |
DECLARE rowId INT; | |
DECLARE employeeId INT; | |
DECLARE efectiveDate DATE; | |
DECLARE rowCount INT; | |
DECLARE resignInfo CURSOR FOR SELECT id, employee_id, effective_date FROM emp_resign WHERE effective_date <= CURDATE() and is_approved = 16 and is_terminated = 0; | |
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; | |
SELECT COUNT(*) INTO @rowCount FROM emp_resign WHERE effective_date <= CURDATE() and is_approved = 16 and is_terminated = 0; | |
IF @rowCount>0 THEN | |
OPEN resignInfo; | |
resign_loop: LOOP | |
IF done THEN | |
LEAVE resign_loop; | |
END IF; | |
FETCH resignInfo into rowId, employeeId, efectiveDate; | |
UPDATE employees SET termination_type = 23, termination_date = efectiveDate, is_active = 2 WHERE id = employeeId; | |
UPDATE emp_resign SET is_terminated = 1 WHERE id = rowId; | |
END LOOP ; | |
END IF; | |
END $$ | |
DELIMITER ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment