我有以下数据进入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中执行此操作?
答案 0 :(得分:1)
数据流转换中有一个数据透视任务。你可以尝试一下,但我会警告你,我们对它的执行情况不太满意。
或者,您可以使用数据流将数据放入登台表,并使用SQL进行透视或在用于创建传入数据源的SQL中执行透视。如果您想在SQl代码中执行此操作,这可能会有所帮助:
select 1 as Item
into #test
union select 2
union select 3
union select 4
union select 5
select STUFF((SELECT ', ' + cast(Item as nvarchar)
FROM #test
FOR XML PATH('')), 1, 1, '')
答案 1 :(得分:1)
我使用Script Component跨行进行字符串连接
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;
}