Data Flow ->> Union All

Wrox的《Professional Microsoft SQL Server 2012 Integration Services》一书中再讲Merge的时候有这样一段解释:

This transformation is similar to the Union All Transformation, but the Merge Transformation has
some restrictions that may cause you to lean toward using Union All:
  1)The data must be sorted before the Merge Transformation. You can do this by using the Sort
    Transformation prior to the merge or by specifying an ORDER BY clause in the source connection.
  2)The metadata must be the same between both paths. For example, the CustomerID column
    can’t be a numeric column in one path and a character column in another path.
  3)If you have more than two paths, you should choose the Union All Transformation.

经过试验,不止Merge对输入双方数据栏位类型上有严格的要求,其实Union All也一样,如果你输入A中的A字段是INT,输入B中的A字段是VARCHAR,这样在Union All中做Mapping的时候是会报错的。

A输入:

Data Flow ->> Union All

B输入:

Data Flow ->> Union All

Union All属性页面做Mapping报错:

Data Flow ->> Union All

不过话虽如此,如果一开始mapping没问题,然而在运行Data Flow前加入一个Execute SQL Task来每次都重建表呢?这样Union All是否会像SQL Server中的Union All一样自动进行数据类型转换呢?

建表的时候A表和B表中的col3都是varchar类型,Union All也认为它是varchar,目标表对应字段col2是varchar类型。然而加了一个Execute SQL Task来每次都重建表,把A表的col3改成int类型。这样做非但没有报错,数据也可以进入到了目标表。说明了这样Int兼容了varchar。

Data Flow ->> Union All

Data Flow ->> Union All

Data Flow ->> Union All

Data Flow ->> Union All

反过来,试下初始化的时候为都为int,然后运行的时候一个改为varchar,这种情况下结果是,无论目标表的对应字段为int或者varchar都能进入表中且package执行成功,说明只要数据本身内容可以转换为int就可以。SSIS或者说Union All组件自动转换数据类型。

上一篇:创建android phonegap项目


下一篇:ZOJ 3607 Lazier Salesgirl 贪心