如何将提取的文件名加载到 SSIS 中的 sql server 表中 [英] how to load extracted file name into sql server table in SSIS

查看:25
本文介绍了如何将提取的文件名加载到 SSIS 中的 sql server 表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个文件夹中有 3 个 csv 文件,其中包含 eid、ename、country 字段,我的 5 个 csv 文件名分别是 test1_20120116_034512、test1_20120116_035512、test1_20120116_035812 等.我想取最后一个要求.基于 timne 戳和修改日期的文件,我已经完成了.现在我想将提取的文件名导入目标表..

i have 3 csv files in a folder which contains eid, ename, country fields, and my 5 csv files names are test1_20120116_034512, test1_20120116_035512,test1_20120116_035812 etc.. my requirement is I want to take lastest file based on timne stamp and modified date, which i have done. Now i want to import the extracted file name into destination table..

我的目标表包含诸如,

文件路径、文件名、eid、ename、国家

我之前在同一个站点上发布过有关此问题的信息,我得到了提取文件名的答案,现在我想将提取的文件名加载到目标表中

I have posted regarding this before in the same site i got an answer for extracting filename, now i want to load the extracted FileName into destination table

我的目标表应该输出为

C:/source test1_20120116_035812 1234 tester USA

推荐答案

在您的 DataFlow 任务中,添加派生列转换.CurrentFile 的值将是文件的完全限定路径.由于您只需要文件名,因此我希望对基本文件夹使用替换功能,然后去除剩余的斜杠.这不会去除文件扩展名,但您可以添加另一个对 REPLACE 的调用并替换一个空字符串

In your DataFlow task, add a Derived Column Transformation. The value of CurrentFile will be the fully qualified path to the file. As you only want the file name, I would look to use a replace function on that with the base folder and then strip the remaining slash. This does not strip the file extension but you can add yet another call to REPLACE and substitute an empty string

  • 派生列名:文件名
  • 派生列:
  • 表达式:REPLACE(REPLACE(@[User::CurrentFile], @[User::RootFolder], ""), "\\", "")

上面期望它看起来像

  • CurrentFile = "C:\source\test1_20120116_035812.csv"
  • RootFolder = "C:\source"

我相信您在您的方法中做了一些我没有做的事情.您应该看到一个关于可能截断的警告,但考虑到本问题和上一个问题中讨论的值,我认为表达式的 4k 限制不会受到关注.

I believe you've done something in your approach that I did not do. You should see a warning about possible truncation but given the values discussed in this and the preceding question, I don't believe the 4k limit on expressions will be of concern.

显示派生列

演示派生列确实有效

我会给你一个 +1 来提供一种我不知道的方法,但你仍然需要添加一个派生列来匹配你提供的格式(基本路径名)

I will give you a +1 for providing an approach I wasn't aware of, but you'll still need to add a derived column to match your provided format (base path name)

从自定义属性提供完整路径.使用上面的 REPLACE 部分删除路径信息,除了使用列 [FileName] 而不是 @[User::CurrentFile]

Full path is provided from the custom properties. Use the above REPLACE section to remove the path info except use the column [FileName] instead of @[User::CurrentFile]

这篇关于如何将提取的文件名加载到 SSIS 中的 sql server 表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆