1. 程式人生 > >sql獲取時間段內的所有日期

sql獲取時間段內的所有日期

SELECT DATEADD(HOUR,1,'2015-01-01 00:00:00') h INTO vinson_h

DELETE vinson_h

DECLARE @num INT=0
DECLARE @h int
SELECT @h=DATEDIFF(HOUR,'2015-01-01 00:00:00',GETDATE())
WHILE(@num<=@h)
BEGIN
    INSERT INTO vinson_h(h) values (DATEADD(HOUR,@num,'2015-01-01 00:00:00'))
    SET @num=@num+1
END

SELECT * FROM vinson_h
ORDER BY h DESC