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)

Android Enthusiasts Meta

Q&A about the site for enthusiasts and power users of the Android operating system

SET DATEFIRST 1;
DECLARE @sDate date
DECLARE @eDate date;
DECLARE @noModificationYears nvarchar(max);
DECLARE @Count int;
SET @sDate = '2020-01-01';
SET @eDate = '2020-12-31';
SET @noModificationYears = '2018,2024,2029,2035';
SET @Count = 1;
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 c1.* from CTE1 c1
  UNION ALL
  Select DATEADD(day, 0, c2.TheDate) as TheDate from CTE1 c2
),
CTE3 As
(
  Select c2.*, ROW_NUMBER() OVER( ORDER BY c2.TheDate) as BucketNo from CTE2 as c2
)

SELECT TheDate, BucketNo,
  CASE
    WHEN 
      BucketNO < 367
    THEN
      'D'
    ELSE
      'W'
    END as PERIND
FROM CTE3 option (maxrecursion 0);

Enter Parameters

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