Skip to content

Instantly share code, notes, and snippets.

@nguyenkims
Created April 4, 2016 10:24
Show Gist options
  • Save nguyenkims/229422b8896d43aaa74bf8b9ed5a97c0 to your computer and use it in GitHub Desktop.
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
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