ssis 派生列
介绍 (Introduction)
In this article, we will show how to convert dates from dd/mm/yyyy to mm/dd/yyyy using the Script component and also derived columns in SSIS. We will also explain when to use a derived column (DC) and when to use the Script Component (SC).
在本文中,我们将展示如何使用Script组件以及SSIS中的派生列将日期从dd / mm / yyyy转换为mm / dd / yyyy。 我们还将说明何时使用派生列(DC)和何时使用脚本组件(SC)。
If you have no experience with the script component or a derived column task, this article is for you. We will do a step by step article.
如果您没有脚本组件或派生列任务的经验,那么本文适合您。 我们将一步一步地做文章。
We will also learn how to handle and fire errors using the script component.
我们还将学习如何使用脚本组件处理和引发错误。
要求 (Requirements)
The following requirements needs to be installed.
需要安装以下要求。
- SSDT for Business Intelligence (with SSIS installed) 用于商业智能的SSDT (已安装SSIS)
入门 (Getting started)
In this example, we will have a file named dates.txt with the following data:
在此示例中,我们将有一个名为dates.txt的文件,其中包含以下数据:
id, salesdate
id,salesdate
1, 13/07/2018
1,13/07/2018
2, 23/06/2019
2,23/06/2019
3, 22/09/2019
3,22/09/2019
This file contains the dates in the format dd/mm/yyyy and we want to convert the date to the format mm/dd/yyyy.
此文件包含格式为dd / mm / yyyy的日期,我们希望将日期转换为格式为mm / dd / yyyy的日期。
Depending on the country, you will find different formats. Here you have a link as a reference related to the format and country:
根据国家/地区,您会找到不同的格式。 在这里,您有一个链接作为与格式和国家/地区相关的参考:
衍生栏 (Derived Column)
We will first use the DC to convert data from the dd/mm/yyyy format to mm/dd/yyyy.
我们将首先使用DC将数据从dd / mm / yyyy格式转换为mm / dd / yyyy。
In SSDT, create a new SSIS Project. In the SSIS project, drag and drop the data flow:
在SSDT中,创建一个新的SSIS项目。 在SSIS项目中,拖放数据流:
Double click the data flow in the design pane and add a Flat file source, flat file destination and the DC task. Join the tasks with an arrow like this:
双击设计窗格中的数据流,然后添加平面文件源,平面文件目标和DC任务。 使用如下箭头连接任务:
Double click the Flat File Source and press the new button:
双击平面文件源,然后按新按钮:
![SSIS Flat File Source Editor](https://www.sqlshack.com/wp-content/uploads/2019/03/ssis-flat-file-source-editor.png)
Specify the path where the dates.txt file is stored. This file contains the date with the dd/mm/yyyy option.
指定dates.txt文件的存储路径。 该文件包含带有dd / mm