SSIS添加分区-动态
Posted ABO
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SSIS添加分区-动态相关的知识,希望对你有一定的参考价值。
主要参考:动态分区
一、前提准备:
1、一个日期存储过程,注意代码可以得到一个月中的最后一天,最终生成时间维度。
USE [DrugDW]
GO
/****** Object: StoredProcedure [dbo].[PROC_DATETIME] Script Date: 2/28 星期二 14:16:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[PROC_DATETIME]
AS
BEGIN
/****** Object: StoredProcedure [dbo].[proc_Dim_date] Script Date: 05/20/2016 11:35:58 ******/
IF OBJECT_ID(\'dbo.Dim_Date\') IS NOT NULL
DROP TABLE dbo.[Dim_Date]
CREATE TABLE [dbo].[Dim_Date](
[DateKey] [int] NULL,
[Date] [datetime] NULL,
[Year] [float] NULL,
[Month] [float] NULL,
[Month EN] [nvarchar](50) NULL,
[Month Short EN] [nvarchar](50) NULL,
[Month CN] [nvarchar](50) NULL,
[Day] [float] NULL,
[Quarter] [float] NULL,
[Quarter EN] [nvarchar](50) NULL,
[Quarter CN] [nvarchar](50) NULL,
[Weekday] [float] NULL,
[Weekday CN] [nvarchar](50) NULL,
[Weekday Short EN] [nvarchar](50) NULL,
[Week of Year] [float] NULL,
[Day of Year] [float] NULL,
[SemiYearly] [nvarchar](50) NULL,
[Period of Ten Days] [nvarchar](10) NULL,
[Period of Index] [nvarchar](2) NULL,
[Weekend] [nvarchar](5) NULL
) ON [PRIMARY]
SET DATEFIRST 7 --设周日为每周的第一天
--向日期表插入数据
DECLARE @b1 DATETIME
set @b1=\'2015-01-01\' --设置起始日期
WHILE @b1< dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0)) --设置截止日期
BEGIN
INSERT INTO dbo.[Dim_Date] (
[DateKey],
[Date],
[Year],
[Month],
[Month EN],
[Month Short EN],
[Month CN],
[Day],
[Quarter],
[Quarter EN],
[Quarter CN],
[Weekday],
[Weekday CN],
[Weekday Short EN],
[Week of Year],
[Day of Year],
[SemiYearly],
[Period of Ten Days],
[Period of Index] ,
[Weekend]
)
VALUES(
CONVERT(NVARCHAR(10),@b1,112), --DateKey 1
@b1, --Date 2
DATEPART(year, @b1), --Year 3
DATEPART(month, @b1), --Month 4
CASE --Month EN 5
when (DATEPART(month, @b1))=\'1\' then \'January\'
when (DATEPART(month, @b1))=\'2\' then \'February\'
when (DATEPART(month, @b1))=\'3\' then \'March\'
when (DATEPART(month, @b1))=\'4\' then \'April\'
when (DATEPART(month, @b1))=\'5\' then \'May\'
when (DATEPART(month, @b1))=\'6\' then \'June\'
when (DATEPART(month, @b1))=\'7\' then \'July\'
when (DATEPART(month, @b1))=\'8\' then \'August\'
when (DATEPART(month, @b1))=\'9\' then \'September\'
when (DATEPART(month, @b1))=\'10\' then \'October\'
when (DATEPART(month, @b1))=\'11\' then \'November\'
else \'December\'
END,
CASE --Month Short En 6
when (DATEPART(month, @b1))=\'1\' then \'Jan\'
when (DATEPART(month, @b1))=\'2\' then \'Feb\'
when (DATEPART(month, @b1))=\'3\' then \'Mar\'
when (DATEPART(month, @b1))=\'4\' then \'Apr\'
when (DATEPART(month, @b1))=\'5\' then \'May\'
when (DATEPART(month, @b1))=\'6\' then \'Jun\'
when (DATEPART(month, @b1))=\'7\' then \'Jul\'
when (DATEPART(month, @b1))=\'8\' then \'Aug\'
when (DATEPART(month, @b1))=\'9\' then \'Sep\'
when (DATEPART(month, @b1))=\'10\' then \'Oct\'
when (DATEPART(month, @b1))=\'11\' then \'Nov\'
else \'Dec\'
END,
CASE --Month CN 7
when (DATEPART(month, @b1))=\'1\' then N\'一月\'
when (DATEPART(month, @b1))=\'2\' then N\'二月\'
when (DATEPART(month, @b1))=\'3\' then N\'三月\'
when (DATEPART(month, @b1))=\'4\' then N\'四月\'
when (DATEPART(month, @b1))=\'5\' then N\'五月\'
when (DATEPART(month, @b1))=\'6\' then N\'六月\'
when (DATEPART(month, @b1))=\'7\' then N\'七月\'
when (DATEPART(month, @b1))=\'8\' then N\'八月\'
when (DATEPART(month, @b1))=\'9\' then N\'九月\'
when (DATEPART(month, @b1))=\'10\' then N\'十月\'
when (DATEPART(month, @b1))=\'11\' then N\'十一月\'
else N\'十二月\'
END,
DATEPART(day, @b1),--day 8
DATEName (qq, @b1),--quarter 9
CASE --quarter en 10
when DATEName (qq, @b1)=\'1\' then \'Q1\'
when DATEName (qq, @b1)=\'2\' then \'Q2\'
when DATEName (qq, @b1)=\'3\' then \'Q3\'
else \'Q4\'
END,
CASE --quarter cn 11
when DATEName (qq, @b1)=\'1\' then N\'一季度\'
when DATEName (qq, @b1)=\'2\' then N\'二季度\'
when DATEName (qq, @b1)=\'3\' then N\'三季度\'
else N\'四季度\'
END,
DATEPART(dw, @b1),--Weekday 12
CASE --Weekday CN 13
when DATEPART(dw, @b1)=1 then N\'星期日\'
when DATEPART(dw, @b1)=2 then N\'星期一\'
when DATEPART(dw, @b1)=3 then N\'星期二\'
when DATEPART(dw, @b1)=4 then N\'星期三\'
when DATEPART(dw, @b1)=5 then N\'星期四\'
when DATEPART(dw, @b1)=6 then N\'星期五\'
else N\'星期六\'
END,
CASE --Weekday Short EN 14 --注意,周日是第一天.
when DATEPART(dw, @b1)=\'1\' then \'Sun\'
when DATEPART(dw, @b1)=\'2\' then \'Mon\'
when DATEPART(dw, @b1)=\'3\' then \'Tue\'
when DATEPART(dw, @b1)=\'4\' then \'Wed\'
when DATEPART(dw, @b1)=\'5\' then \'Thu\'
when DATEPART(dw, @b1)=\'6\' then \'Fri\'
else \'Sat\'
END,
DATEName (wk, @b1),--week of year 15
DATEName (dy, @b1),--day of year 16
CASE --SemiYearly 17
when DATEPART(month, @b1)<=6 then N\'上半年\'
else N\'下半年\'
END,
CASE --Period of Ten Days 18
when DATEName (dd, @b1)<=10 then N\'上旬\'
when DATEName (dd, @b1)>20 then N\'下旬\'
else N\'中旬\'
END,
CASE --Period of Ten Days 19
when DATEName (dd, @b1)<=10 then N\'1\'
when DATEName (dd, @b1)>20 then N\'3\'
else N\'2\'
END,
CASE --Is it Weekend? 20
when DATEPART(dw, @b1)=\'1\' then \'周末\'
when DATEPART(dw, @b1)=\'7\' then \'周末\'
else \'平时\'
END
)
--日期加1天
set @b1=DATEADD(day, 1, @b1)
END
end
2、一个事实表:
3、构建好的Cube,并且无分区(有分区也无妨,这里只是排除干扰,容易理解):
4、准备SSIS参数:
二、利用SSIS动态构建分区
最终效果
2.1 、执行SQL任务
SQLStatement代码:
SELECT \'DrugDW\' AS DataSoureID,--数据源
\'Drug DW\' AS CubeName,--分区来自哪一个cube
\'Drug DW\' AS CubeID,
\'以上是关于SSIS添加分区-动态的主要内容,如果未能解决你的问题,请参考以下文章
动态 SSIS 包将 N 个表从 Oracle 加载到 SQL