【SQL】 Sql查询两个日期之间所有的星期
select d2.weekRange,convert(varchar(10),d2.FirstDay,21) FirstDay,convert(varchar(10),d2.EndDay,21) EndDay from ( select datepart(WEEK,d.dates) weekRange ,dateadd(Day,1-(DATEPART(Weekday,d.dates)+@@DATEFIRST-1)%7,d.dates) FirstDay ,dateadd(wk, datediff(wk,0,d.dates), 6) EndDay from ( select dateadd(dd,number,@starttime) AS dates from master..spt_values where type='p' and dateadd(dd,number,@starttime)<@endtime ) d ) d2 group by d2.weekRange,d2.FirstDay,d2.EndDay order by FirstDay
微信扫码查看本文
发表评论