Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active January 13, 2021 22:51
Show Gist options
  • Save stevewithington/7b144c26c078c56359db7f6bc1963bdb to your computer and use it in GitHub Desktop.
Save stevewithington/7b144c26c078c56359db7f6bc1963bdb to your computer and use it in GitHub Desktop.
SQL: Date Dimension Table
USE [SomeDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[DimDate](
[DateId] [int] IDENTITY(1,1) NOT NULL,
[Date] [date] NOT NULL,
[Year] [int] NOT NULL,
[Month] [int] NOT NULL,
[Quarter] [int] NOT NULL,
[YearMonth] [int] NOT NULL,
[YearQuarter] [int] NOT NULL,
[MonthName] [varchar](255) NOT NULL,
[MonthNameShort] [char](255) NOT NULL,
[MonthDayFirst] [date] NOT NULL,
[MonthDayMid] [date] NOT NULL,
[MonthDayLast] [date] NOT NULL,
[WeekOfYear] [int] NOT NULL,
[DayOfWeek] [int] NOT NULL,
[DayOfMonth] [int] NOT NULL,
[DayOfYear] [int] NOT NULL,
[DayName] [varchar](255) NOT NULL,
[DayNameShort] [varchar](255) NOT NULL,
[WeekEndDay] [int] NOT NULL,
[HolidayFedFlag] [int] NOT NULL,
[HolidayFedDesc] [varchar](255) NOT NULL,
[Roll12Month] [int] NULL,
[RollYearCalendar] [int] NULL,
[RollQuarter] [int] NULL,
[RollMonth] [int] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment