Q&A about the site for scholars and enthusiasts of literature
SET DATEFIRST 1; DECLARE @from_date date DECLARE @to_date date; DECLARE @noModificationYears nvarchar(max); SET @from_date = '2018-01-01'; SET @to_date = '2020-12-31'; ;with CTE As ( SELECT DATEADD(day, 0, @from_date) AS the_date UNION ALL SELECT DATEADD(day, 1, the_date) AS TheDate FROM CTE WHERE the_date < @to_date ) SELECT @noModificationYears = ( SELECT CONCAT(DATEPART(year, the_date), ',') FROM CTE GROUP BY DATEPART(week, the_date), DATEPART(year, the_date) HAVING COUNT(DATEPART(year, the_date)) = 7 AND DATEPART(week, the_date) = '1' FOR XML PATH('') ) OPTION (MAXRECURSION 0); Select @noModificationYears as years;