I want to create a calendar date table in SQL Server for 2002 to 2011, whi开发者_运维百科ch 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?
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)
精彩评论