SET DATEFIRST 1; DECLARE @sDate date DECLARE @eDate date;...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Literature Meta

Q&A about the site for scholars and enthusiasts of literature

SET DATEFIRST 1;
DECLARE @sDate date
DECLARE @eDate date;
DECLARE @noModificationYears nvarchar(max);
SET @sDate = '2018-01-01';
SET @eDate = '2020-12-31';

with CTE1 As  
(  
    Select DATEADD(day, 0, @sDate) as TheDate
    UNION ALL  
    Select DATEADD(day, 1, TheDate) as TheDate from CTE1  
    where TheDate < @eDate
)
,CTE2 AS (
      SELECT DATEPART(week, TheDate) AS WeekOfYear, DATEPART(year, TheDate) AS TheYear
      FROM CTE1 GROUP BY DATEPART(week, TheDate), DATEPART(year, TheDate) 
      HAVING Count(DATEPART(year, TheDate)) = 7 AND DATEPART(week, TheDate) = '1'     
)

SELECT * from CTE2 option (maxrecursion 0);

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results