报表(补全不存在记录的日期)
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