DimDate populate data

日期维度

任何一个数据仓库都应该有一个日期维度。

因为很少有不需要通过日期维度看数据的情况存在。

日期维度的好处是,你可以通过他连接各个事实表,然后在报表端传送报表参数的时候,

直接自动过滤日期维度的相关值,而不需要自己写query.

去掉了西班牙语和法语的那些列。

You know that there are some holes in the sample database, DW2008R2 DIMDATE table.

So I take my own dimdate. Just remove some columns not used.

CREATE TABLE [dbo].[DimDate](

[DateKey] [int] NOT NULL,

[FullDateAlternateKey] [date] NOT NULL,

[DayNumberOfWeek] [tinyint] NOT NULL,

[EnglishDayNameOfWeek] [nvarchar](10) NOT NULL,

[DayNumberOfMonth] [tinyint] NOT NULL,

[DayNumberOfYear] [smallint] NOT NULL,

[WeekNumberOfYear] [tinyint] NOT NULL,

[EnglishMonthName] [nvarchar](10) NOT NULL,

[MonthNumberOfYear] [tinyint] NOT NULL,

[CalendarQuarter] [tinyint] NOT NULL,

[CalendarYear] [smallint] NOT NULL,

[CalendarSemester] [tinyint] NOT NULL,

[FiscalQuarter] [tinyint] NOT NULL,

[FiscalYear] [smallint] NOT NULL,

[FiscalSemester] [tinyint] NOT NULL,

CONSTRAINT [PK_DimDate_DateKey] PRIMARY KEY CLUSTERED

(

[DateKey] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],

CONSTRAINT [AK_DimDate_FullDateAlternateKey] UNIQUE NONCLUSTERED

(

[FullDateAlternateKey] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

BEGIN TRAN

declare @startdate date = ‘2005-01-01‘,

@enddate date = ‘2015-12-31‘

Declare @datelist table (FullDate date)

while @startdate <= @enddate

Begin

Insert into @datelist (FullDate)

Select @startdate

Set @startdate = dateadd(dd,1,@startdate)

end

Insert into dbo.DimDate

(DateKey,

FullDateAlternateKey,

DayNumberOfWeek,

EnglishDayNameOfWeek,

DayNumberOfMonth,

DayNumberOfYear,

WeekNumberOfYear,

EnglishMonthName,

MonthNumberOfYear,

CalendarQuarter,

CalendarYear,

CalendarSemester,

FiscalQuarter,

FiscalYear,

FiscalSemester)

select convert(int,convert(varchar,dl.FullDate,112)) as DateKey,

dl.FullDate,

datepart(dw,dl.FullDate) as DayNumberOfWeek,

datename(weekday,dl.FullDate) as EnglishDayNameOfWeek,

datepart(d,dl.FullDate) as DayNumberOfMonth,

datepart(dy,dl.FullDate) as DayNumberOfYear,

datepart(wk, dl.FUllDate) as WeekNumberOfYear,

datename(MONTH,dl.FullDate) as EnglishMonthName,

Month(dl.FullDate) as MonthNumberOfYear,

datepart(qq, dl.FullDate) as CalendarQuarter,

year(dl.FullDate) as CalendarYear,

case datepart(qq, dl.FullDate)

when 1 then 1

when 2 then 1

when 3 then 2

when 4 then 2

end as CalendarSemester,

case datepart(qq, dl.FullDate)

when 1 then 3

when 2 then 4

when 3 then 1

when 4 then 2

end as FiscalQuarter,

case datepart(qq, dl.FullDate)

when 1 then year(dl.FullDate)

when 2 then year(dl.FullDate)

when 3 then year(dl.FullDate) + 1

when 4 then year(dl.FullDate) + 1

end as FiscalYear,

case datepart(qq, dl.FullDate)

when 1 then 2

when 2 then 2

when 3 then 1

when 4 then 1

end as FiscalSemester

from @datelist dl ;

commit tran;
时间: 2024-10-14 05:07:17

DimDate populate data的相关文章

An Implementation of Double-Array Trie

Contents What is Trie? What Does It Take to Implement a Trie? Tripple-Array Trie Double-Array Trie Suffix Compression Key Insertion Key Deletion Double-Array Pool Allocation An Implementation Download Other Implementations References What is Trie? Tr

tpcc-mysql安装、使用、结果解读

tpcc-mysql的业务逻辑及其相关的几个表作用如下: New-Order:新订单,主要对应 new_orders 表 Payment:支付,主要对应 orders.history 表 Order-Status:订单状态,主要对应 orders.order_line 表 Delivery:发货,主要对应 order_line 表 Stock-Level:库存,主要对应 stock 表 其他相关表: 客户:主要对应 customer 表 地区:主要对应 district 表 商品:主要对应 it

获取本机MSSQL保存凭证

本文转自王子博客:http://www.cnblogs.com/killbit/p/4355950.html 首先要感谢哥们对我的指点,多谢. 当我们遇到类似情况下,如何获取保存在MSSQL工具里的凭证呢?  //如果对方连接地址后面加了IP\sqlexpress 连接的时候你也记得加上,不然即使密码正确,也会说登录失败. 通过和哥们讨论研究分析以及查找资料,知道了密码存放的地方: C:\Users\Administrator\AppData\Roaming\Microsoft\Microsof

【mysql】使用tpcc-mysql进行压力测试

Tpcc-mysql是percona基于tpcc衍生出来专用于mysql基准测试的产品 ,可以参见 <高性能MySQL第三版> 一.安装 rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm yum install bzr bzr branch lp:~percona-dev/perconatools/tpcc-mysql 查看 README [[email protected] tpc

Apache Sqoop - Overview Apache Sqoop 概述

使用Hadoop来分析和处理数据需要将数据加载到集群中并且将它和企业生产数据库中的其他数据进行结合处理.从生产系统加载大块数据到Hadoop中或者从大型集群的map reduce应用中获得数据是个挑战.用户必须意识到确保数据一致性,消耗生产系统资源,供应下游管道的数据预处理这些细节.用脚本来转化数据是低效和耗时的方式.使用map reduce应用直接去获取外部系统的数据使得应用变得复杂和增加了生产系统来自集群节点过度负载的风险. 这就是Apache Sqoop能够做到的.Aapche Sqoop

Bulk Insert:将文本数据(csv和txt)导入到数据库中

将文本数据导入到数据库中的方法有很多,将文本格式(csv和txt)导入到SQL Server中,bulk insert是最简单的实现方法 1,bulk insert命令,经过简化如下 BULK INSERT schema_name . table_name FROM 'data_file' WITH ( FIELDTERMINATOR = 'field_terminator', ROWTERMINATOR = 'row_terminator', DATAFILETYPE=‘WideChar’ )

将csv和txt 数据导入到数据库中

将文本数据导入到数据库中,最简单的选择是:Excel使用OpenSet,csv和txt 使用bulk insert来实现 1,使用OpenRowSet将Excel导入到数据库中 参考<OpenRowSet 用法> 2,使用bulk insert 将txt数据导入到数据库中,文本数据使用Tab分割Column,使用换行符分割row. --create staging table create table dbo.txt_staging ( col1 nvarchar(255), col2 nva

Beginning Scala study note(6) Scala Collections

Scala's object-oriented collections support mutable and immutable type hierarchies. Also support functional higher-order operations such as map, filter, and reduce that let you use expression-oriented programming in collections. Higher-order operatio

flex 字符串与base64 转换

/* Base64 - 1.1.0 Copyright (c) 2006 Steve Webster Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, in