generate days from date range

后端 未结 29 2488
渐次进展
渐次进展 2020-11-21 05:19

I would like to run a query like

select ... as days where `date` is between \'2010-01-20\' and \'2010-01-24\'

And return data like:

29条回答
  •  灰色年华
    2020-11-21 06:10

    improved with weekday an joining a custom holiday table microsoft MSSQL 2012 for powerpivot date table https://gist.github.com/josy1024/cb1487d66d9e0ccbd420bc4a23b6e90e

    with [dates] as (
        select convert(datetime, '2016-01-01') as [date] --start
        union all
        select dateadd(day, 1, [date])
        from [dates]
        where [date] < '2018-01-01' --end
    )
    select [date]
    , DATEPART (dw,[date]) as Wochentag
    , (select holidayname from holidaytable 
    where holidaytable.hdate = [date]) 
    as Feiertag
    from [dates]
    where [date] between '2016-01-01' and '2016-31-12'
    option (maxrecursion 0)
    

提交回复
热议问题