sql server 查询某个时间段共有多少周及每周的日期段
时间:2021-07-01 10:21:17
帮助过:3人阅读
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
sql server 查询某个时间段共有多少周及每周的日期段
标签:and rom code 分享 ber values add blog 查询