Re: [SQL ] 請問TSQL如何取range工作天數及日期?

作者: cutekid (可愛小孩子)   2018-12-17 12:56:13
;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的語法嗎?
作者: oherman (qq)   2018-12-17 13:38:00
謝謝cute大,好厲害

Links booklink

Contact Us: admin [ a t ] ucptt.com