您的位置:首页 > 数据库

使用sql查询生成开始到结束日期之间的所有日期

2017-03-17 10:48 399 查看
利用select * from master.dbo.spt_values

declare @StartDate DATETIME = '2015/05/01'

declare @EndDate DATETIME ='2015/06/03'

select dateadd(day,number,@StartDate) as dt

from master.dbo.spt_values  where type ='P'

and number <=DATEDIFF(day, @StartDate,   @EndDate)

/*

dt

-----------------------

2015-05-01 00:00:00.000

2015-05-02 00:00:00.000

2015-05-03 00:00:00.000

2015-05-04 00:00:00.000

2015-05-05 00:00:00.000

2015-05-06 00:00:00.000

2015-05-07 00:00:00.000

2015-05-08 00:00:00.000

...

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: