日历表 - 月份的周数

发布于 2024-08-26 00:16:19 字数 1502 浏览 6 评论 0原文

我有一个日历表,其中包含 2000 年到 2012 年的数据(2012 年不是故意的!)。我只是意识到我没有月份的周数(例如 1 月 1,2,3,4 月 2 月 1,2,3,4)

我如何计算一个月中的周数来填写此表?

这是表架构

CREATE TABLE [TCalendar] (
    [TimeKey] [int] NOT NULL ,
    [FullDateAlternateKey] [datetime] NOT NULL ,
    [HolidayKey] [tinyint] NULL ,
    [IsWeekDay] [tinyint] NULL ,
    [DayNumberOfWeek] [tinyint] NULL ,
    [EnglishDayNameOfWeek] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [SpanishDayNameOfWeek] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [FrenchDayNameOfWeek] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [DayNumberOfMonth] [tinyint] NULL ,
    [DayNumberOfYear] [smallint] NULL ,
    [WeekNumberOfYear] [tinyint] NULL ,
    [EnglishMonthName] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [SpanishMonthName] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [FrenchMonthName] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [MonthNumberOfYear] [tinyint] NULL ,
    [CalendarQuarter] [tinyint] NULL ,
    [CalendarYear] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [CalendarSemester] [tinyint] NULL ,
    [FiscalQuarter] [tinyint] NULL ,
    [FiscalYear] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [FiscalSemester] [tinyint] NULL ,
    [IsLastDayInMonth] [tinyint] NULL ,
    CONSTRAINT [PK_TCalendar] PRIMARY KEY  CLUSTERED 
    (
        [TimeKey]
    )  ON [PRIMARY] 
) ON [PRIMARY]
GO

I have a calendar table with data from year 2000 to 2012 (2012 wasn't intentional!). I just realize that I don't have the week number of month (e.g In January 1,2,3,4 February 1,2,3,4)

How do I go about calculating the week numbers in a month to fill this table?

Here is the table schema

CREATE TABLE [TCalendar] (
    [TimeKey] [int] NOT NULL ,
    [FullDateAlternateKey] [datetime] NOT NULL ,
    [HolidayKey] [tinyint] NULL ,
    [IsWeekDay] [tinyint] NULL ,
    [DayNumberOfWeek] [tinyint] NULL ,
    [EnglishDayNameOfWeek] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [SpanishDayNameOfWeek] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [FrenchDayNameOfWeek] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [DayNumberOfMonth] [tinyint] NULL ,
    [DayNumberOfYear] [smallint] NULL ,
    [WeekNumberOfYear] [tinyint] NULL ,
    [EnglishMonthName] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [SpanishMonthName] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [FrenchMonthName] [nvarchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [MonthNumberOfYear] [tinyint] NULL ,
    [CalendarQuarter] [tinyint] NULL ,
    [CalendarYear] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [CalendarSemester] [tinyint] NULL ,
    [FiscalQuarter] [tinyint] NULL ,
    [FiscalYear] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
    [FiscalSemester] [tinyint] NULL ,
    [IsLastDayInMonth] [tinyint] NULL ,
    CONSTRAINT [PK_TCalendar] PRIMARY KEY  CLUSTERED 
    (
        [TimeKey]
    )  ON [PRIMARY] 
) ON [PRIMARY]
GO

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林很绿却致人迷途 2024-09-02 00:16:19
update TCalendar 
set = WeekNumberOfMonth = DATEDIFF(week, DATEADD(MONTH, DATEDIFF(MONTH, 0, FullDateAlternateKey), 0), FullDateAlternateKey) +1
update TCalendar 
set = WeekNumberOfMonth = DATEDIFF(week, DATEADD(MONTH, DATEDIFF(MONTH, 0, FullDateAlternateKey), 0), FullDateAlternateKey) +1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文