作者cutekid (可爱小孩子)
看板Database
标题Re: [SQL ] 请问TSQL如何取range工作天数及日期?
时间Mon Dec 17 12:56:13 2018
;with tb1 as(
select date = convert(datetime,'20180101')
union all
select date + 1
from tb1
where date < '20181231'
)
select *,total = count(*) over (partition by 1)
from tb1
where datepart(dw,date) not in (1,7)
option (maxrecursion 0)
※ 引述《oherman (qq)》之铭言:
: 资料库名称:ms sql
: 资料库版本:2016
: 内容/问题描述:
: 请问TSQL如何取range工作天数及日期?
: 例如: 2018/01/01 至 2018/12/31 工作天数几天
: (去除六、日,不要管特殊国定假日如劳工节、中秋节…等)
: 及 2018/01/01 至 2018/12/31 工作天日期
: (如2018/01/01,2018/01/02....,不含六、日的日期)
: 有尽量不要写function的语法吗?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 61.223.49.25
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Database/M.1545022576.A.1EA.html
1F:推 oherman: 谢谢cute大,好厉害 12/17 13:38