79358684

Date: 2025-01-15 15:02:04
Score: 0.5
Natty:
Report link

The one checked was so close to what I needed. Had to make a few changes. 1st I needed more than a month (6 years). Then I need to add the OPTION line at the bottom. This allowed me to join the sales date on this CTE.

declare @mindate datetime
declare @maxdate datetime
set @mindate = '2019-01-01' set @maxdate = '2022-06-17'
; WITH AllDateDOW AS (
        SELECT  DATEADD(day ,-(DAY(@mindate)-1),@mindate) as AllDATE, 
                DATENAME(dw, DATEADD(day, -(DAY(@mindate) - 1), @mindate)) as DOWDAY
        UNION ALL
        SELECT  DATEADD(day, 1, AllDATE),
                DATENAME(dw, DATEADD(dw, 1, AllDATE))
        FROM    AllDateDOW
        WHERE   DATEADD(day, 1, AllDATE) <= @maxdate
    )
    -- SELECT *     FROM AllDateDOW
OPTION (MAXRECURSION 2190) -- This needs to be after the Order By. 2190=6 Years --

Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Nathan Brick