报表(补全不存在记录的日期)

DECLARE @daysNum INT
DECLARE @currentDay DATETIME
DECLARE @index INT;
DECLARE @NewTable TABLE (
currentDate DATETIME,
realDate DATETIME
)


SET @daysNum = 30
SET @index = 1;
WHILE @index < @daysNum
BEGIN
    SET @currentDay = ( SELECT DATEADD(DAY, @index, GETDATE()) )
    SET @index  = @index + 1
    INSERT @NewTable ( currentDate, realDate ) VALUES  (CONVERT(VARCHAR(10), @currentDay,112), @currentDay )
END

SELECT  * FROM @NewTable

posted @ 2014-12-24 09:45  Space Tian  阅读(302)  评论(0编辑  收藏  举报