sql 语句

select number+1 as wknum,dateadd(wk,number,'2017-01-01') as firstday,
(case when year(dateadd(d,-1,dateadd(wk,number+1,'2017-01-01')))>2017 then '2017-12-31'
else dateadd(d,-1,dateadd(wk,number+1,'2017-01-01')) end) as sevenday
from master..spt_values
where type='p' and year(dateadd(wk,number,'2017-01-01'))=2017

结果如图

sql server 查询某个时间段共有多少周及每周的日期段-LMLPHP

sql server 查询某个时间段共有多少周及每周的日期段-LMLPHP

本文引自:http://www.myexception.cn/sql-server/327685_3.html

05-11 17:02