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
结果如图
本文引自:http://www.myexception.cn/sql-server/327685_3.html
时间: 2024-10-09 12:58:30