根据开始日期和结束日期插入行数

时间:2015-05-30 05:19:19

标签: mysql

我找到了sql server的代码片段,实际上还要为mysql定制它,同时传递父表id(event_id)。

SQL Server版本

CREATE PROC dbo.t_test 
@StartDate DATETIME,
@EndDate DATETIME
AS

WHILE @StartDate <= @EndDate
BEGIN
    INSERT INTO YourTable(YourDateField) VALUES (@StartDate)
    SET @StartDate = DATEADD(d,1,@StartDate)
END

MySQL版本尝试

CREATE PROCEDURE `day` (IN start DATE, IN end DATE, IN event_id INT)
BEGIN
    WHILE start <= end DO
        INSERT INTO day(date, event_id) VALUES(start, event_id);
        SET start = start + 1;
    END WHILE;
END

我的桌面日结构是

day (id, date, event_id)

0 个答案:

没有答案