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)

Monero Meta

Q&A about the site for developers and users of the secure, private and untraceable cryptocurrency Monero

SET DATEFIRST 1;
   DECLARE @sDate date
   DECLARE @eDate date;
   DECLARE @noModificationYears nvarchar(max);
   SET @sDate = '2019-01-01';
   SET @eDate = '2055-12-31';
   SET @noModificationYears = '2018,2024,2029,2035';
 
   with CTE1 As 
   ( 
       Select DATEADD(day, 0, @sDate) as TheDate
       UNION ALL 
       Select DATEADD(day, 1, TheDate) as TheDate from CTE1 
       where TheDate < @eDate
   )
 
   SELECT
       c1.TheDate AS Date,
       DATEPART(year, c1.TheDate) AS DateYear,
       DATEPART(month, c1.TheDate) AS DateMonth,
       DATEPART(week, c1.TheDate) as DateWeek,
       datepart(year, dateadd(dd, -datepart(dw, c1.TheDate) + 1, c1.TheDate)) as CalculatedWeekYear,
       CASE
       WHEN
           CHARINDEX(cast(DATEPART(year, TheDate) as varchar(8000)), @noModificationYears) > 0
       THEN
           DATEPART(week, c1.TheDate)
       ELSE
           CASE
           WHEN
               DATEPART(week, c1.TheDate) != 1
           THEN
               DATEPART(week, c1.TheDate) - 1
           ELSE
               CASE
               WHEN
               CHARINDEX(cast((DATEPART(year, TheDate) - 1) as varchar(8000)), @noModificationYears) = 0
               THEN
                   DATEPART(week, CONCAT(datepart(year, TheDate) - 1, '-12-31')) - 1
               ELSE
                   DATEPART(week, CONCAT(datepart(year, TheDate) - 1, '-12-31'))
               END
           END
       END AS CalculatedWeek
   FROM CTE1 AS c1
   option (maxrecursion 0);

Enter Parameters

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