Skip to content

Instantly share code, notes, and snippets.

@josy1024
Last active July 14, 2016 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josy1024/cb1487d66d9e0ccbd420bc4a23b6e90e to your computer and use it in GitHub Desktop.
Save josy1024/cb1487d66d9e0ccbd420bc4a23b6e90e to your computer and use it in GitHub Desktop.
day generator for powerpivot with weekday and holiday subselect!!! mssql 2012, powerpivot excel 2016
/* SOURCE:
http://stackoverflow.com/questions/2157282/generate-days-from-date-range
https://gist.github.com/josy1024/cb1487d66d9e0ccbd420bc4a23b6e90e
+ subselect for holiday subselect
*/
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 (y,[date]) as Jahr
, DATEPART (m,[date]) as Monat
, 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment