Last active
August 29, 2015 14:16
-
-
Save jonathanvx/64cb8320ab83d3264893 to your computer and use it in GitHub Desktop.
Update By Date - Stored Procedure
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 $$ | |
drop procedure if exists update_by_date$$ | |
CREATE PROCEDURE update_by_date(IN startdate DATE, IN enddate date) | |
PROC:BEGIN | |
DECLARE idate date; | |
DECLARE cr BIGINT; | |
DECLARE done INT DEFAULT FALSE; | |
-- requires data_dimension table - be found in my github repo | |
DECLARE curs1 CURSOR FOR SELECT date FROM date_dimension WHERE date between startdate and enddate; | |
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; | |
OPEN curs1; | |
read_loop: LOOP | |
FETCH curs1 INTO idate; | |
IF done THEN | |
LEAVE read_loop; | |
END IF; | |
-- do something | |
-- WHERE date = idate; | |
END LOOP; | |
CLOSE curs1; | |
END$$ | |
delimiter ; | |
-- call update_by_date('2014-01-01','2015-01-01'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment