ssis 有条件拆分

This article explores the SSIS Conditional Split Transform task to split data into multiple destinations based on the specified conditions.

本文探讨了SSIS条件拆分转换任务,该任务可根据指定条件将数据拆分到多个目标。

介绍 (Introduction)

We apply different logics on data in SQL Server tables to fulfill the requirements of the end-users. We might apply different analytical, logical, arithmetic conditions and logic on data. Let’s say you have a requirement to split the data into multiple tables depending upon some conditions. You can use a T-SQL function to write, but it might take time to do the development work. You need to rework on the code in case there are logic changes.

我们对SQL Server表中的数据应用不同的逻辑,以满足最终用户的需求。 我们可能会对数据应用不同的分析,逻辑,算术条件和逻辑。 假设您需要根据某些条件将数据拆分为多个表。 您可以使用T-SQL函数进行编写,但是可能需要一些时间来完成开发工作。 如果发生逻辑更改,则需要对代码进行重新处理。

SSIS always comes handy in such situations and provides a solution for us with minimal complexity. Further, we can use it to take inputs from multiple data sources such as Excel, CSV, OLE DB, ODBC, TXT, etc. We can also use it to prepare output in different formats without writing complex programming codes.

在这种情况下,SSIS总是很方便,并为我们提供了最小的复杂性的解决方案。 此外,我们可以使用它来获取来自多个数据源的输入,例如Excel,CSV,OLE DB,ODBC,TXT等。我们还可以使用它来准备不同格式的输出,而无需编写复杂的编程代码。

环境细节 (Environment Details)

  • We will use the AdventureWorks2017 sample database in this article 我们将在本文中使用AdventureWorks2017示例数据库
  • Download and install SQL Server Data Tools (SSDT) for Visual Studio to install it 下载并安装用于Visual StudioSQL Server数据工具(SSDT)进行安装

需求 (Requirement)

We have Employee data in the AdventureWorks2017 database. It contains a view vEmployee to fetch employee records.

我们在AdventureWorks2017数据库中有员工数据。 它包含一个视图vEmployee以获取员工记录。

Execute the following query to view the sample data.

执行以下查询以查看样本数据。

SELECT *FROM [AdventureWorks2017].[HumanResources].[vEmployee];

We want to split data based on the CountryRegionName column in different tables.

我们要基于不同表中的CountryRegionName列拆分数据。

  • For employees belonging to the United Kingdom, insert data into the table [United Kingdom] 对于属于英国的雇员,将数据插入表[英国]
  • For employees belonging to the United States, insert data into the table [United States] 对于属于美国的雇员,将数据插入表[美国]
  • For employees belonging to Germany, insert data into the table [Germany] 对于属于德国的雇员,将数据插入表中[德国]
  • The rest of the data (not satisfying above conditions) should go to the [default] table 其余数据(不满足上述条件)应转到[默认]表

创建一个SSIS包以根据条件拆分数据 (Create an SSIS package to split data based on conditions)

将SSIS条件拆分转换添加到数据流 (Add an SSIS Conditional Split Transformation to the Data Flow)

Let’s use the SSIS package to satisfy the above conditions and split data in multiple tables.

让我们使用SSIS包来满足上述条件并将数据拆分到多个表中。

  • Open SQL Server Data Tool and go to File->New -> Project

    打开SQL Server数据工具,然后转到“文件”->“新建”->“项目”

    It opens the following New Project Window. Select the Integration Service project and assign an appropriate name to the project. You can also specify a location where the project will save

    它打开下面的“新建项目”窗口。 选择Integration Service项目,然后为该项目分配一个适当的名称。 您还可以指定项目将保存的位置

  • Click Ok, and it prepares the project and opens the following project window

    单击确定,它会准备项目并打开以下项目窗口

  • Click on SSIS Toolbox (left-hand side) and drag the Data Flow Tasks to the Control Flow area

    单击SSIS工具箱(左侧)并将“数据流任务”拖到“控制流”区域

  • Double click on the Data Flow Tasks, and it moves to Data Flow Tab as per the following screenshot

    双击“数据流任务”,然后按照以下屏幕截图将其移至“数据流”选项卡

  • In the Data Flow area, drag the OLE DB Source from the SSIS Toolbox. We use OLE DB Source because our sample data is in the SQL Server Database tables

    在“数据流”区域中,从SSIS工具箱中拖动OLE DB源。 我们使用OLE DB Source,因为我们的示例数据在SQL Server数据库表中

  • Right-click on the OLE DB Source and rename the task with an appropriate name. You can skip this step if you do not want to rename the source

    右键单击OLE DB源,然后使用适当的名称重命名该任务。 如果您不想重命名源,可以跳过此步骤

  • Right-click on the Source data and click on Edit. It opens the OLE DB Source Editor. In this editor, we need to define the SQL Server instance connection, database and object (table\view) details

    右键单击源数据,然后单击编辑。 它打开OLE DB源编辑器。 在此编辑器中,我们需要定义SQL Server实例连接,数据库和对象(表\视图)的详细信息

We do not have any existing connections in this SSIS package. Click on the New, provide SQL Instance details, and select the database in which an object exists. You can also click on Test Connection to verify that connection is successful.

该SSIS包中没有任何现有连接。 单击“新建”,提供“ SQL实例”详细信息,然后选择对象所在的数据库。 您也可以单击“ 测试连接”以验证连接是否成功。

If the Test Connection is successful, you get the following message.

如果测试连接成功,则会出现以下消息。

Select the table or view from the drop-down list.

从下拉列表中选择表或视图。

Click Ok, and you can see the Source data task does not contain any cross icon. It shows that configuration is successful for this task.

单击“确定”,您将看到“源数据”任务不包含任何十字形图标。 它表明此任务的配置成功。

将SSIS条件拆分转换添加到数据流 (Add a SSIS Conditional Split Transformation to the Data Flow)

It is the central part of this article. We need to add a Conditional Split Transformation task in the SSIS package to split the data. The Conditional Split Transformation task checks for the specified condition. It moves the data to an appropriate destination depending upon the condition.

这是本文的中心部分。 我们需要在SSIS包中添加条件拆分转换任务以拆分数据。 条件拆分转换任务检查指定条件。 它将根据条件将数据移动到适当的目的地。

Drag the SSIS Conditional Split task from the SSIS Toolbox.

从SSIS工具箱中拖动SSIS条件拆分任务。

Now, Connect the Source Data (OLE DB Source) to the Conditional Split transformation task. To connect, drag the green arrow from the Source Data to the SSIS Conditional Split as shown in the following image.

现在,将源数据(OLE DB源)连接到条件拆分转换任务。 要进行连接,将绿色箭头从源数据拖动到SSIS条件拆分,如下图所示。

Now, we need to define the conditions in the SSIS Conditional Split transformation task. Double click on the Conditional Split and it opens the following Conditional Split transformation Editor.

现在,我们需要在SSIS条件拆分转换任务中定义条件。 双击条件拆分,它将打开以下条件拆分转换编辑器。

The Conditional Split transformation Editor has three sections.

条件拆分转换编辑器分为三个部分。

  1. We can use system variables and query output columns in the expressions to split the data flow 我们可以在表达式中使用系统变量和查询输出列来拆分数据流
  2. We can define the various functions such as Mathematical, Date & Time function, Logical function, Null function 我们可以定义各种函数,例如数学,日期和时间函数,逻辑函数,空函数
  3. In this section, we define the conditions to define the split of data. We should be careful in defining the conditions and these conditions should not overlap with each other. If the data satisfy one, it should not satisfy other conditions 在本节中,我们定义了定义数据拆分的条件。 我们在定义条件时应该小心,这些条件不应相互重叠。 如果数据满足一个条件,则不应满足其他条件

Specify the conditions in the SSIS Conditional Split transformation Editor. We need to use equal operator (==) in the split conditions and values in the double quotes as shown below.

在SSIS条件拆分转换编辑器中指定条件。 我们需要在拆分条件中使用等于运算符(==),并在双引号中使用值,如下所示。

The specified conditions are as follows:

指定条件如下:

    • CountryRegionName == “United Kingdom” CountryRegionName ==“英国”
    • CountryRegionName == ” United States ” CountryRegionName ==“美国”
    • CountryRegionName == ” Germany” CountryRegionName ==“德国”
  • The rest of the data (not satisfying above conditions) should go to the [default] table 其余数据(不满足上述条件)应转到[默认]表

将数据流目标添加到数据流 (Adding Data Flow Destinations to the Data Flow)

After the SSIS Conditional Split Transformation task, we need to add a destination path for each of the split conditions data.

完成SSIS条件拆分转换任务后,我们需要为每个拆分条件数据添加目标路径。

Drag the OLE DB Destination task in the data flow from the SSIS toolbox.

从SSIS工具箱中将OLE DB目标任务拖到数据流中。

Drag the green arrow from the Conditional Split to OLE DB Destination. It opens the following window.

将绿色箭头从条件拆分拖动到OLE DB目标。 它打开以下窗口。

In the output, select the output name defined in the split conditional transformation task earlier.

在输出中,选择先前在分割条件转换任务中定义的输出名称。

For a better understanding, I renamed the OLE DB Destination as the United Kingdom.

为了更好地理解,我将OLE DB目标重命名为英国。

You can still see a Red Cross icon in the destination United Kingdom.

您仍然可以在目标英国看到红十字会图标。

Double click on the United Kingdom task and it opens the following OLE DB Destination editor.

双击UK任务,它将打开以下OLE DB Destination编辑器。

If we have an existing table in which we want to insert data, we can select the table from the drop-down list. Otherwise, click on the New, and it shows the script as per the input data.

如果我们有一个现有表要在其中插入数据,则可以从下拉列表中选择该表。 否则,单击“新建”,它会根据输入数据显示脚本。

Click OK, and it shows the name of the destination table as shown in the following image.

单击“确定”,它显示目标表的名称,如下图所示。

Click on the Mappings, and you can view the mapping between the input and output columns. You can make a change in the column mappings if required.

单击映射,您可以查看输入和输出列之间的映射。 如果需要,您可以在列映射中进行更改。

Click Ok, and you can see that conditional task specifying condition 1.

单击确定,您将看到该条件任务指定条件1。

You can follow similar steps and configure the OLE DB destination to satisfy other conditions as well.

您可以按照类似的步骤,并配置OLE DB目标以满足其他条件。

The complete SSIS package looks as per the following screenshot.

完整的SSIS软件包按照以下屏幕截图显示。

Let’s execute the SSIS package and see how it works. For executing the package, click on the Start.

让我们执行SSIS包,看看它是如何工作的。 要执行包,请单击“开始”。

You can see a green tick on each task, and it shows the package is successful.

您可以在每个任务上看到一个绿色的勾号,并且它表明程序包已成功。

In the screenshot above, we also note the following.

在上面的屏幕截图中,我们还注意以下几点。

  • Total Input Rows: 290 输入总行数:290
  • Conditional Split for the United Kingdom: 1 英国的有条件拆分:1
  • Conditional Split for the United States: 284 美国的有条件拆分:284
  • Conditional Split for Germany: 1 德国的有条件拆分:1
  • Data that does not meet any specified condition: 4 不符合任何指定条件的数据:4

Suppose we want to further split the data for the United States based on the column StateProvinceName column. The conditions on which we want to split United Data are as follows.

假设我们要根据StateProvinceName列进一步拆分美国的数据。 我们要分割United Data的条件如下。

Split data for Washington, California, and others in a separate table.

在单独的表格中拆分华盛顿,加利福尼亚和其他地区的数据。

In the following screenshot, we have another SSIS Conditional Split transformation task to further split the United States data as per the condition.

在下面的屏幕快照中,我们还有另一个SSIS条件拆分转换任务,用于根据条件进一步拆分美国数据。

Execute the SSIS package now, and we can see that United States data (Row 284) further divides into the following values.

现在执行SSIS包,我们可以看到美国数据(行284)进一步划分为以下值。

  • California: 2 加州:2
  • Washington: 275 华盛顿:275
  • Others: 7 其他:7

结论 (Conclusion)

In this article, we explored SSIS Conditional Split Transformation to split the data as per specified conditions. We can use it for the source and destination as SQL Server tables. We can use multiple inputs and output formats such as flat files, spreadsheets or any destination supported by SSIS. You should explore and be familiar with this task to do the data transformation without any complicated programming.

在本文中,我们探讨了SSIS条件拆分转换以根据指定条件拆分数据。 我们可以将其用作SQL Server表的源和目标。 我们可以使用多种输入和输出格式,例如平面文件,电子表格或SSIS支持的任何目标。 您应该探索并熟悉此任务,以进行数据转换而无需任何复杂的编程。

翻译自: https://www.sqlshack.com/ssis-conditional-split-transform-overview/

ssis 有条件拆分

ssis 有条件拆分_SSIS条件拆分转换概述相关推荐

  1. ssis 列转换_SSIS组播转换概述

    ssis 列转换 This article explores the SSIS Multicast Transformation for creating different logical copi ...

  2. ssis 有条件拆分_SSIS条件拆分概述

    ssis 有条件拆分 SQL Server Integration Services or SSIS is used as an ETL tool to extract-transform-load ...

  3. ACM中的整数K拆分 (有条件限制 无条件限制 插板法 URAL-1036 HDU-6397)

    整数的K拆分 整数K拆分示例 在程序设计竞赛中,我们会经常遇到一类整数 KKK 拆分的问题. 例如:求 NNN 个非负整数之和为 SSS 的方案数(每个数字都小于 MMM). 对于这类问题,分为两种情 ...

  4. 将工作表按条件拆分成多个工作表或者工作簿,包含快速拆分与精致拆分

    将一个工作表按条件拆分成多个工作表或者拆分成工作簿,包含快速拆分与精致拆分. 精致拆分可以保留所有格式,速度慢一点. 可以将一个工作表拆分成多个工作表,也可以直接拆分成多个独立文件. 将工作表按条件拆 ...

  5. 【DB笔试面试617】在Oracle中,和“表达式和条件评估”相关的查询转换有哪些?...

    ♣题目 部分 在Oracle中,和"表达式和条件评估"相关的查询转换有哪些? ♣答案部分 (一)逻辑转换 1LHR@orclasm > SELECT /*+FULL(A) F ...

  6. python学习笔记1-print()函数与变量+数据类型与转换+条件判断与条件嵌套+input()函数

    print()函数与变量 1.基本句式 print('千寻') 2.引号的用法 3.转义字符 print('let\'s go') 4.变量和赋值 5.小结 数据类型与转换 字符串 整数 浮点数 数据 ...

  7. ssis修改数据库数据_SSIS平衡数据分配器概述

    ssis修改数据库数据 In this article, we will give a brief overview of SSIS Balanced Data Distributor (BDD). ...

  8. ssis lookup_SSIS中的LOOKUP转换概述

    ssis lookup We will explore Lookup Transformation in SSIS in this article for incremental data loadi ...

  9. 查看ssis执行日志_SSIS包日志记录概述

    查看ssis执行日志 This article gives an overview of the different methods of SQL Server SSIS Package Loggin ...

最新文章

  1. 创建sql自定义的函数及商品分页sql存储过程
  2. 全球及中国教育行业投资动态与发展决策建议报告2022版
  3. bzoj1833: [ZJOI2010]count 数字计数 codevs1359 数字计数
  4. python 报ImportError: Install xlrd = 1.0.0 for Excel support错误
  5. ITK:使用曲率流平滑RGB图像
  6. 【数据结构总结】第三章:栈和队列(线性结构)
  7. Unity 2017 Game Optimization 读书笔记(1)Scripting Strategies Part 1
  8. Linux Kconfig及Makefile学习
  9. javaBean【02】javaBean与表单应用
  10. cba比赛比分预测_【CBA直播】深圳vs广东前瞻:深圳战广东再掀反攻?
  11. css div设置inline-block后 div顶部对齐
  12. 怎么把python模型部署到线上_如何将机器学习模型成功部署到.Net环境中
  13. android 调用系统下载apk,如何在自己的App中调用Android系统自带的安装/卸载程序...
  14. 完整解决方案:让你的IIS 支持PHP方法
  15. 手机端html返回顶部,vue实现移动端返回顶部
  16. uinput 用法 android 上层使用uinput 的用法来模拟 input 事件
  17. Crontab定时任务表达式
  18. 三色球问题,python解决
  19. 【Android】AlarmManager实现定时任务和取消任务
  20. MAC 启动jar失败 显示 Unable to access jarfile xxx.jar

热门文章

  1. Java 获取昨天、当前、明天的时间
  2. 《程序员修炼之道》读后感02
  3. 关于.vbs文件恶搞,小伙伴电脑的
  4. 询问任意区间的min,max,gcd,lcm,sum,xor,or,and
  5. SQL Server 2005导入导出存储过程
  6. 好用的chrome插件总结
  7. 关于React的一切(updating...)
  8. axios.post请求出错:Request header field content-type is not allowed by Access-Control-Allow-Headers in……
  9. php7.2 session,PHP 7.2 Warning: “Cannot change session name when session is active”
  10. 到退休单位没有通知,半年后通知退休,这半年是否算工龄?