SSIS:数据将分隔行转换为字段
我有一个包含相关数据行的表,我需要在 SSIS 包中转换这些数据,但我不知道如何处理它。
在此表中,彼此相关的行由包含管道字符的行分隔,例如
测试行 1_1
测试线1_2
测试线1_3
|
测试线2_1
测试线2_2
测试线2_3
|
测试线3_1
测试线3_2
测试行 3_3
等。
我需要将其移至表中,并将每组行的行连接成由管道分隔符分隔的一行。因此,从上面的示例中,我需要在另一个表中结束:
test line 1_1 test line 1_2 test line 1_3
测试线2_1 测试线2_2 测试线2_3
测试线3_1 测试线3_2 测试线3_3
我不知道该怎么做。我考虑过导出到文本文件,然后使用管道分隔符重新导入 - 这可行,但我将处理数百万行,所以我宁愿避免这种开销,必须有一种方法可以在 SSIS 中做到这一点,但目前我不知道怎么办。
非常感谢任何帮助,谢谢。
I have got a table containing rows of related data which I need to transform within an SSIS package and I am not sure how to go about it.
In this table the rows that are related to each other are separated by a row that contains a pipe character e.g.
test line 1_1
test line 1_2
test line 1_3
|
test line 2_1
test line 2_2
test line 2_3
|
test line 3_1
test line 3_2
test line 3_3
etc..
I need to move this into a table and concatenate the lines of each group of rows into one line separated by the pipe delimiter. So from the above example I need to end up with in another table:
test line 1_1 test line 1_2 test line 1_3
test line 2_1 test line 2_2 test line 2_3
test line 3_1 test line 3_2 test line 3_3
I am not sure how to do it. I thought about exporting to a text file then reimporting using the pipe delimiter - this would work but I will be dealing with millions of rows and so I would rather aviod this overhead, there must be a way to do it in SSIS but at the moment I am not sure how.
Any help much appreciated, thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建使用源组件的数据流任务。源将使用 SQL 语句检索数据。
然后,添加脚本组件作为转换。脚本组件必须设置为异步。选择脚本组件的输入和输出选项卡,然后选择输出 0。将 SynchronousInputID 设置为 None。这将允许组件输出与输入行数不同的行数。在“输出列”分支下方添加一个新列。
在脚本组件中,您可以根据需要连接数据。默认情况下,输入缓冲区为 Row,输出缓冲区为 Output0Buffer。您可以使用 Row.NextRow() 获取下一个输入行,并使用 Output0Buffer.AddRow() 添加新的输出行。
给定示例数据,您可以将输入数据添加到输出缓冲区,直到出现“|”出现。或者,如果适合您的数据,您可以使用计数器。
You can create a Data Flow task that uses a Source component. The source will retrieve the data with a SQL statement.
Then, add a Script component as a transformation. The script component must be set as asynchronous. Select the Inputs and Outputs tab of the Script component, and then select Output 0. Set the SynchronousInputID to None. This will allow the component to output a different number of rows than the number of rows input. Add a new column below the Output Columns branch.
In your script component, you can concatenate the data as you wish. By default, your input buffer will be Row and the output buffer will be Output0Buffer. You can use Row.NextRow() to get the next input row and Output0Buffer.AddRow() to add new output rows.
Given your sample data, you can add input data to the output buffer until a '|' appears. Or, you can use a counter if that fits your data.