how to load extracted file name into sql server table in SSIS

前端 未结 2 649
深忆病人
深忆病人 2020-12-06 07:14

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_035

2条回答
  •  旧时难觅i
    2020-12-06 07:40

    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

    • Derived Column Name: filename
    • Derived Column:
    • Expression: REPLACE(REPLACE(@[User::CurrentFile], @[User::RootFolder], ""), "\\", "")

    The above expects it to look like

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

    Edit

    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.

    Displaying the derived column

    Derived columns

    Demonstrating the derived column does work

    Data flow via derived column

    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)

    Flat File custom properties

    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]

    Full path provided

提交回复
热议问题