Reputation: 11
I want to create a calendar date table in SQL Server for 2002 to 2011, which would minimally contain all of the dates for each year, along with whether each date is a week day or week-end day.
Any ideas on where I can find such data online? (or elsewhere)? How can I import or generate such a table?
Upvotes: 1
Views: 696
Reputation: 138960
set datefirst 1
;with Cal as
(
select cast('20020101' as datetime) as dt
union all
select dt+1
from Cal
where dt < cast('20111231' as datetime)
)
select
dt as [Date],
case datepart(dw, dt)
when 6 then 1
when 7 then 1
else 0
end as Weekend
from Cal
option (maxrecursion 0)
Upvotes: 3