SSIS将多列合并为一个带空值的列

时间:2014-07-03 15:58:56

标签: sql ssis

我之前已经问过类似的问题,但我有一个独特的案例,以前的答案都没有解决。

我有一个数据库行,其中有5个注释列,我想将它们组合成一个。 例如:

    ID     NAME    CMT1     CMT2    CMT3    CMT 4   CMT5
    1    John     BLAH     BLAH    null    null    null
    2    Mary     BLAH     null    null    null    null
    3    Sue      BLAH     BLAH    BLAH    BLAH    BLAH

我想看到以下内容:

    ID      NAME    CombinedComment
    1       John    BLAH BLAH
    2       Mary    BLAH
    3       Sue     BLAH BLAH BLAH BLAH BLAH

现在提出警告。

1. I cannot use SQL to join the data. The data comes from a linked server via a stored procedure. This is the usual response to this problem.
2. I cannot modify the stored procedure.
3. I am using a Derived Column and using the following:

    Combined      CMT1 + " " + CMT2  + " " + CMT3  + " " + CMT4  + " " + CMT5

This works only for rows that have a value in ALL 5 comment fields. 

总而言之,我希望Combined Comment列适用于所有行,即使其他注释字段中有null也是如此。

1 个答案:

答案 0 :(得分:1)

在Derived列转换中使用

ISNULL(CMT1)? "":CMT1 

OR

REPLACENULL(CMT1,"")

围绕评论字段。