【问题标题】:Looking for calendar data to import into SQL Server查找要导入 SQL Server 的日历数据
【发布时间】:2011-04-29 03:23:55
【问题描述】:

我想在 SQL Server 中为 2002 年到 2011 年创建一个日历日期表,其中至少包含每年的所有日期,以及每个日期是工作日还是周末。

关于在哪里可以在线找到此类数据的任何想法? (或其他地方)?如何导入或生成这样的表?

【问题讨论】:

标签: sql-server date calendar


【解决方案1】:
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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-21
    • 2011-12-30
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    相关资源
    最近更新 更多