salix/db/changes/10110-postCampaign/00-rangeDateInfo.sql

42 lines
1.0 KiB
MySQL
Raw Normal View History

2019-11-22 07:23:31 +00:00
DROP procedure IF EXISTS `vn`.`rangeDateInfo`;
DELIMITER $$
CREATE PROCEDURE `vn`.`rangeDateInfo` (vStarted DATE, vEnded DATE)
BEGIN
/**
* Crea una tabla temporal con las fechas
* desde una fecha inicial a una final
* @param vStarted fecha inicial
* @param vEnded fecha final
*/
2019-11-22 07:23:31 +00:00
DECLARE vDated DATE DEFAULT vStarted;
2019-11-22 07:23:31 +00:00
DROP TEMPORARY TABLE IF EXISTS tmp.rangeDate;
CREATE TEMPORARY TABLE tmp.rangeDate(
`dated` DATE,
`period` INT,
`month` INT,
`year` INT,
`day` INT,
`week` INT,
`yearMonth` INT
2019-11-22 07:23:31 +00:00
)
ENGINE = MEMORY;
WHILE vDated <= vEnded DO
INSERT INTO tmp.rangeDate
SET `dated` = vDated,
`period` = YEAR(vDated) * 100 + WEEK(vDated, 1),
`month` = MONTH(vDated),
`year` = YEAR(vDated),
`day` = DAY(vDated),
`week` = WEEK(vDated, 1),
`yearMonth` = YEAR(vDated) * 100 + MONTH(vDated);
2019-11-22 07:23:31 +00:00
SET vDated = DATE_ADD(vDated, INTERVAL 1 DAY);
END WHILE;
END$$
DELIMITER ;