根据起止日期 循环出日期

 1 DECLARE @begindate DATETIME ,

 2     @enddate DATETIME ,

 3     @sql VARCHAR(1000)

 4 

 5 SELECT  @begindate = '2014-12-01' ,

 6         @enddate = '2015-01-31'

 7 FROM    calendar

 8 WHERE   id = 'b8f3e1d8-e208-40b4-abc9-20d9ac9f5b29'

 9 SET @sql = 'select top ' + RTRIM(DATEDIFF(day, @begindate, @enddate) + 1)

10     + ' id=identity(int,0,1) into t_date from sysobjects,syscolumns'

11 EXEC(@sql)

12 SELECT  DATEADD(day, id, @begindate) Date

13 FROM    t_date

14 

15 DROP TABLE t_date

 

你可能感兴趣的:(日期)