时间维度表的建立
来源:互联网 发布:资金盘网站源码 编辑:程序博客网 时间:2024/04/30 08:55
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description:<Description,,>
-- =============================================
create PROCEDURE [dbo].[Create_time_dimension]
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
begin try
drop table [time_dimension]
end try
begin catch
end catch
CREATE TABLE [dbo].[time_dimension] (
[time_id] [int] IDENTITY (1, 1) NOT NULL ,
[the_date] [datetime] NULL ,
[the_day] [nvarchar] (15) NULL ,
[the_month] [nvarchar] (15) NULL ,
[the_year] [smallint] NULL ,
[day_of_month] [smallint] NULL ,
[week_of_year] [smallint] NULL ,
[month_of_year] [smallint] NULL ,
[quarter] [nvarchar] (2) NULL ,
[fiscal_period] [nvarchar] (20) NULL
) ON [PRIMARY]
DECLARE @WeekString varchar(12),
@dDate SMALLDATETIME,
@sMonth varchar(20),
@iYear smallint,
@iDayOfMonth smallint,
@iWeekOfYear smallint,
@iMonthOfYear smallint,
@sQuarter varchar(2),
@sSQL varchar(100),
@adddays int
SELECT @adddays = 1 --日期增量(可以自由设定)
SELECT @dDate = '01/01/2006' --开始日期
WHILE @dDate < '12/31/2012' --结束日期
BEGIN
SELECT @WeekString = DATENAME (dw, @dDate)
SELECT @sMonth=DATENAME(mm,@dDate)
SELECT @iYear= DATENAME (yy, @dDate)
SELECT @iDayOfMonth=DATENAME (dd, @dDate)
SELECT @iWeekOfYear= DATENAME (week, @dDate)
SELECT @iMonthOfYear=DATEPART(month, @dDate)
SELECT @sQuarter = 'Q' + CAST(DATENAME (quarter, @dDate)as varchar(1))
INSERT INTO time_dimension(the_date, the_day, the_month, the_year,
day_of_month,
week_of_year, month_of_year, quarter) VALUES
(@dDate, @WeekString, @sMonth, @iYear, @iDayOfMonth, @iWeekOfYear,
@iMonthOfYear, @sQuarter)
SELECT @dDate = @dDate + @adddays
END
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
- 时间维度表的建立
- 时间维度表的建立
- 建立时间维度表的脚本
- 数据仓库的时间维度表 Sql
- 数据仓库的时间维度
- mysql时间维度表。
- 算法时间维度的计算
- 使用CTE递归的方式实现时间维度表
- 基于OLAP的时间维度设计
- mysql创建时间维度的sql脚本
- 建时间维度表(oracle)
- mysql中生成时间维度表
- 【SQL】sql 时间维度表相关
- SSAS建立父子维度
- as 2008里关于父子维度的建立
- 创建时间维度数据
- 数据仓库时间维度
- 时间维度创建
- 如何在HI3515上搭建NFS开发调试环境
- maven 入门 详解 --->总结
- DOM动态删除TABLE多行
- Windows 性能问题诊断(5)
- GPIO简介
- 时间维度表的建立
- Windows 性能问题诊断(6)
- VS说某个符号没有被定义,怎么办?
- html页面全屏
- 优雅的谢幕
- eclipse myeclipse debug详解
- iframe嵌套父页面访问子页的方法
- Linux 进程的挂起和恢复
- Extjs 自动完成