SSIS 对数据排序

发布时间:2020-06-10 08:11:42 作者:胡壮壮
来源:网络 阅读:661

SSIS 对数据排序有两种方式,一种是使用Sort组件,一种是使用sql command的order by clause进行排序。

一,使用Sort组件进行排序

SSIS 对数据排序

SortType:升序 ascending,降序 descending

SortOrder:排序列的位置,从1开始依次递增,

Remove wors with duplicate sort values:如果排序列重复,是否删除重复的行,这不同于distinct,distinct是输出的所有列不重复,选中该选项,只是保证排序列(输出列的一部分)不重复。

该属性可以从Sort Transformation Advanced Editor中查看和设置

SSIS 对数据排序

 

二,使用sql command的order by clause对数据进行排序

Step1,使用OLEDB提供排序的数据,必须是经过排序的数据

select *from dbo.course c with(nolock)order by c.cid asc,c.score desc

 

 SSIS 对数据排序

 

Step2,打开OLEDB的Advanced Editor,查看Input and Output Properties选项卡

1,点击OLEDB Source Ouput,设置IsSorted属性为True,该属性设置为true不会对数据排序,只是告知下游组件,该输出数据已经排序。

如果将IsSorted属性设置为True,实际数据并没有排序,在package 运行时会出错,所以必须提供已经排序的数据(在sql 子句中使用order by进行排序)

2,点击Output Columns,逐个设置排序列(Order by Column_List)的SortKeyPosition属性

SortKeyPosition属性有Sort Position和Direction 两个metadata:

正整数表示按照升序排序,0表示不是排序列,负整数表示按照降序排序,数字代表排序列的序号

例如以下的sql语句

select Col_1,Col_2,Col_3,Col_4from dbo.TableNameorder Col_1 asc, Col_2 desc,Col_3 desc

在Output Columns中需要逐个设置,Col_1,Col_2,Col_3,Col_4的SortKeyPosition
由于Col_1,Col_2,Col_3是排序列,序号从1依次递增,而Col_4不是排序列,所以SortKeyPosition的配置如下

Col_1 的SortKeyPosition是 1,第一个排序列,且按照升序排序

Col_2 的SortKeyPosition是 -2,第二个排序列,且按照降序排序

Col_3 的SortKeyPosition是 3,第三个排序列,且按照升序排序

Col_4 的SortKeyPosition是 0,不是排序列

SSIS 对数据排序

SSIS 对数据排序

SSIS 对数据排序

 

 

MSDN官方文档

Sort Data for the Merge and Merge Join Transformations

In Integration Services, the Merge and Merge Join transformations require sorted data for their inputs. The input data must be sorted physically, and sort options must be set on the outputs and the output columns in the source or in the upstream transformation. If the sort options indicate that the data is sorted, but the data is not actually sorted, the results of the merge or merge join operation are unpredictable.

You can sort this data by using one of the following methods:

If the data is string data, both the Merge and Merge Join transformations expect the string values to have been sorted by using Windows collation. To provide string values to the Merge and Merge Join transformations that are sorted by using Windows collation, use the following procedure.

To provide string values that are sorted by using Windows collation

 

Setting Sort Options on the Data

There are two important sort properties that must be set for the source or upstream transformation that supplies data to the Merge and Merge Join transformations:

If you use a Sort transformation to sort the data, the Sort transformation sets both of these properties as required by the Merge or Merge Join transformation. That is, the Sort transformation sets the IsSorted property of its output to True, and sets the SortKeyPosition properties of its output columns.

However, if you do not use a Sort transformation to sort the data, you must set these sort properties manually on the source or the upstream transformation. To manually set the sort properties on the source or upstream transformation, use the following procedure.

To manually set sort attributes on a source or transformation component

  1. In SQL Server Data Tools (SSDT), open the Integration Services project that contains the package you want.

  2. In Solution Explorer, double-click the package to open it.

  3. On the Data Flow tab, locate the appropriate source or upstream transformation, or drag it from the Toolbox to the design surface.

  4. Right-click the component and click Show Advanced Editor.

  5. Click the Input and Output Properties tab.

  6. Click <component name> Output, and set the IsSorted property to True.

                               Note                        

    If you manually set the IsSorted property of the output to True and the data is not sorted, there might be missing data or bad data comparisons in the downstream Merge or Merge Join transformation when you run the package.

  7. Expand Output Columns.

  8. Click the column that you want to indicate is sorted and set its SortKeyPosition property to a nonzero integer value by following these guidelines:

    As an example of how to set the SortKeyPosition property, consider the following Transact-SQL statement that loads data in a source:

    SELECT * FROM MyTable ORDER BY ColumnA, ColumnB DESC, ColumnC                  

    For this statement, you would set the SortKeyPosition property for each column as follows:

Repeat step 8 for each sorted column.Click OK.To save the updated package, click Save Selected Items on the File menu.


推荐阅读:
  1. SSIS 包配置
  2. SSIS Execute SQL Task 用法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ssis sis 数据排序

上一篇:如何在代码里打开Android手机通知状态栏

下一篇:电脑上同时安装Python2和Python3

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》