为了得到所有Sunday dates
和Saturday dates
之间给定date ranges
我使用iterative solution
如下,
create TABLE #Dayweeks (id int IDENTITY(1,1),StartWeek DATETIME, EndWeek DATETIME) DECLARE @wkstartdate datetime = '2015-12-06', @wkenddate datetime = '2016-04-05' WHILE (@wkstartdate <= @wkenddate) BEGIN INSERT INTO #Dayweeks ( StartWeek, EndWeek ) SELECT @wkstartdate, DATEADD(wk,DATEDIFF(wk,0,@wkstartdate),6)-1 SELECT @wkstartdate = DATEADD(dd,7,@wkstartdate) END
我想知道如何使用它set based approach
.有没有办法通过使用获得上述结果set based approach
?
我使用迭代解得到的输出如下.