Created
April 4, 2016 10:24
-
-
Save nguyenkims/229422b8896d43aaa74bf8b9ed5a97c0 to your computer and use it in GitHub Desktop.
Fill up table "dates" with all the days from 1/1/2016 till 12/31/2016
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
DROP PROCEDURE IF EXISTS fillupdate; | |
DELIMITER // | |
CREATE PROCEDURE fillupdate() | |
BEGIN | |
DECLARE nbdate INT DEFAULT 0; | |
DECLARE dt DATETIME DEFAULT 0; | |
SET dt = '2016-01-01'; | |
while nbdate < 365 do | |
set nbdate = nbdate + 1; | |
set dt = date_add(dt, interval 1 day); | |
INSERT INTO dates(dt) values(dt); | |
end while; | |
END; | |
// | |
DELIMITER ; | |
call fillupdate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment