开发者

Looking for calendar data to import into SQL Server

开发者 https://www.devze.com 2023-03-02 00:39 出处:网络
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-e

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消