如何从SSI中的文件名获取日期

发布于 2025-01-27 13:53:58 字数 282 浏览 1 评论 0原文

我的SSIS包具有数据流任务,并为每个循环容器执行SQL任务组件。软件包流量为,日期流量任务(平面文件 - >条件拆分以将数据插入SQL Server表中) - >执行SQL任务(对插入的数据执行一些SQL操作,并在一个最终分析表中插入计算值) 。文件名就像name1_name2_yyyymmdd_1234.txt。我想从文件名中获取日期,然后在SQL Server中的表中插入该日期值。我正在尝试使用派生的列进行操作,但无法弄清楚我们的何处可以保存它,以便它可以在Decute SQL任务中的插入语句中可用,该任务是在数据流任务之后。

I have SSIS package with data flow task and execute SQL task components in For each loop container. Package flow is, Date flow task(flat file--> Conditional split to insert data into SQL server tables)-->Execute SQL task(perform some SQL operations on inserted data and insert the calculated values in one final analysis table) . File name is like name1_name2_yyyymmdd_1234.txt. I want to fetch the date from file name and insert that date value in table in SQL Server as FileDate. I am trying to do it using derived column but unable to figure our where will I save it so that it will be available in Insert statement in Execute SQL Task which is after Data flow task.

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

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

发布评论

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

评论(1

苍白女子 2025-02-03 13:53:58

这应该在数据流之外,但在foreach循环中进行。

将两个参数(软件包范围)传递到脚本任务。一个带有@fileName(仅读取)的一个,并存储@filedate(read/write)。

Split将创建一个基于0的数组,您只关心第三件。

Dts.Variables["fileDate"].Value = DateTime.ParseExact(Dts.Variables["fileName"].Value.Split('_')[2]
                         ,"yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);

现在,您可以在任何地方使用@filedate。

This should be done outside the dataflow but within the ForEach loop.

Pass in two parameters (package scope) to a script task. One with the @filename (read only) from the forloop and to store the @fileDate (read/write).

Split will create a 0-based array in which you only care about the third piece.

Dts.Variables["fileDate"].Value = DateTime.ParseExact(Dts.Variables["fileName"].Value.Split('_')[2]
                         ,"yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);

Now you can use @fileDate anywhere you would like.

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