如何編寫一個查詢以返回兩個日期之間的工作日星期的開始和結束日期?SQL Server查詢返回工作日星期開始,結束日期
例子:
declare
@startDate date = '2013-07-01'
, @endDate date = '2013-09-30'
SELECT WeekData(@startDate, @endDate)
結果:
Name, Week1Start, Week1End, Week2Start, Week2End, Week3Start, Week3End, Week4Start, Week4End, Week5Start, Week5End
---------------------------------------------------------------------------------------------------------------------------------------------------
'July 2013', '2013-07-01', '2013-07-05', '2013-07-08', '2013-07-12', '2013-07-15', '2013-07-19', '2013-07-22', '2013-07-26', '2013-07-29', '2013-07-31'
'August 2013', '2013-08-01', '2013-08-02', '2013-08-05', '2013-08-09', '2013-08-12', '2013-08-16', '2013-08-19', '2013-08-23', '2013-08-26', '2013-08-30'
'September 2013', '2013-09-02', '2013-09-06', '2013-09-09', '2013-09-13', '2013-09-16', '2013-09-20', '2013-09-23', '2013-08-27', '2013-09-30', '2013-09-30'
一個工作周從星期一開始或每月的第一天,並在週五或每月的最後一天結束。
可能重複[什麼是獲得的最好方式SQL中兩個日期之間的開始日期和結束日期](http://stackoverflow.com/questions/12752136/what-is-the-best-way-to-get-start-date-and-enddate -of-的周間兩日) –