Easiest way to populate a temp table with dates between and including 2 date parameters

前端 未结 8 1679
旧时难觅i
旧时难觅i 2020-11-27 06:34

What is the easiest way to populate a temp table with dates including and between 2 date parameters. I only need the 1st day of the month dates.

So for example if @S

8条回答
  •  情话喂你
    2020-11-27 06:50

    declare @StartDate date = '2014-01-01';
    declare @EndDate date = '2014-05-05';
    
    ;WITH cte AS (
        SELECT @StartDate AS myDate
        UNION ALL
        SELECT DATEADD(day,1,myDate) as myDate
        FROM cte
        WHERE DATEADD(day,1,myDate) <=  @EndDate
    )
    SELECT myDate
    FROM cte
    OPTION (MAXRECURSION 0)
    

提交回复
热议问题