如何读取和更改SSIS脚本组件中的列名称

发布于 2024-09-30 07:53:24 字数 425 浏览 0 评论 0原文

来源:ADO.Net(TSQL -query):查询将返回数据集(列名称是月份,即 JAN FEB MAR APR JUN JUL .... DEC)

目标:Excel

如果您运行该包,它将传输数据和 Excel列名称如下 一月 二月 三月 .. 十二月 -->这是预期结果

新要求: 1.声明一个名为“Year”的变量,值为 2010。这可能会有所不同。 2.在数据流中使用脚本组件,我必须将列名称更改为末尾有_2010,即JAN_2010 FEB_2010 MAR_2010 ... DEC_2010(2010应该来自变量) 3. 脚本组件中名为“ProcessInputRow”的方法中需要编码的内容。 请更新我如何实现这一点,即更改脚本组件中的输入列名称 并将其转移到目的地?

提前致谢

Source:ADO.Net(TSQL -query): Query will return the dataset(column names are months i.e. JAN FEB MAR APR JUN JUL .... DEC)

Destination: Excel

If you run the package it is transfering the data and the excel is having the column names like
JAN FEB MAR .. DEC --> this is as expected result

New Requirement:
1.Declare a variable called "Year" and value is 2010. this may vary.
2. using the Script Component in data flow i have to change the column names to have _2010 at the end i.e JAN_2010 FEB_2010 MAR_2010 ... DEC_2010(2010 should come from variable)
3. what needs to be coded inside a method called "ProcessInputRow" in script component.
Please update me how to achieve this i.e changing the input column names in Script Component
and transfer that to destination?.

Thanks in Advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风轻花落早 2024-10-07 07:53:24

您实际上无法以编程方式添加列或更改列名称,因为列名称稍后需要在数据流中保持静态。

您可以做的是通过进入脚本转换编辑器上的输入和输出区域,打开输出 0,然后在输出列区域中添加 12 列,向输出添加新列。然后,您可以将每个输入列中的数据分配给脚本中相应的输出列。

通过派生列转换可以更好地实现这一点。

话虽这么说,我有一种感觉,你真正想要的不是 JAN_2010、FEB_2010 等,而是当前年份附加到月份名称后。实际上,您无法让动态列名称流经数据流。

但是您可以尝试以下操作:Excel 列名称实际上只是 Excel 电子表格第一行的内容。创建一个流,在电子表格顶部输出一行并包含正确的数据(使用脚本组件作为数据源),然后运行数据流以添加数据。

You can't actually add columns or change the column names programmatically because the names of the columns will need to be static later on down the data flow.

What you can do is add new columns to your output by going into the Inputs and Outputs area on the Script Transformation Editor, opening the Output 0 and then adding 12 columns in the Output columns area. Then you would assign the data from each of your input columns to the appropriate output columns in your script.

This would be better accomplished with a Derived Column transformation.

All that being said, I have a feeling that what you really want is not JAN_2010, FEB_2010, etc. but the current year appended to the name of the month. You can't actually have dynamic column names flowing through your data flow.

However you could try the following: Excel column names are really just the contents of the first row of the excel spreadsheet. Create a flow that outputs a single row at the top of the spreadsheet with the correct data (use the script component as a data source) and then run your data flow to add the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文