SQL中给定某一日期段生成所有日期数据

时间:2021-05-18 14:05:02
SQL中给定某一日期段生成所有日期数据
SELECT DateAdd(day,number,'2014-09-29')
  FROM master..spt_values
 WHERE type = 'p'
   AND number <= DateDiff(day,'2014-09-29',GetDate())

运行结果:

2014-09-29 00:00:00.000
2014-09-30 00:00:00.000
2014-10-01 00:00:00.000
2014-10-02 00:00:00.000
2014-10-03 00:00:00.000
2014-10-04 00:00:00.000
2014-10-05 00:00:00.000
2014-10-06 00:00:00.000
2014-10-07 00:00:00.000
2014-10-08 00:00:00.000
2014-10-09 00:00:00.000
2014-10-10 00:00:00.000
2014-10-11 00:00:00.000
2014-10-12 00:00:00.000
2014-10-13 00:00:00.000
2014-10-14 00:00:00.000