一尘不染

SSIS转换(几乎像枢轴一样)

sql

我将以下数据输入到SSIS中

Set   Value
---   -------
1     One
1     Two
1     Three
2     Four
2     Five
2     Six

我想将其转换为阅读

Set   ValueList
---   -------
1     One, Two, Three
2     Four, Five, Six

如何在SSIS中执行此操作?


阅读 139

收藏
2021-03-17

共1个答案

一尘不染

我使用脚本组件在各行之间进行字符串连接

string TagId = "-1";
string TagList = "";
bool IsFirstRow = true;

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    if (Row.TAGSId.ToString() == TagId)
    {
        TagList += Row.TAG + ",";
    }
    else
    {
        if (IsFirstRow)
        {
            Output0Buffer.AddRow();
            IsFirstRow = false;
        }

        TagId = Row.TAGSId.ToString();
        TagList = Row.TAG.ToString() + ",";
    }

    Output0Buffer.TagId = int.Parse(TagId);
    Output0Buffer.TagList = TagList;
    Output0Buffer.TagLength = TagList.Length;

    //variable used in subsequent queries
    this.Variables.TagList = TagList;
}
2021-03-17