報表(補全不存在記錄的日期)

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


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 )
ENDab

SELECT  * FROM @NewTable

相關文章
相關標籤/搜索