SSIS 2016 how can I insert the name of the text file with the columns of the text file?

sqlagent007
sqlagent007 used Ask the Experts™
on
I have a very simple data load process that I am running. I loop through text files in a folder on a file share and load the data into a database table. For this example let's say the file contains 3 columns: NAME | PHONE | AMOUNT. I would like to add a column to my DB table named FILE_INSERTED and have that populated with the name of the file.

Example: a file named MY_FILE_20171101.txt has 50 rows of data. I would like the column FILE_INSERTED for all 50 of those rows populated with MY_FILE_20171101.txt.

Currently the database table looks like this:
 NAME | PHONE | AMOUNT
jane|520-234-1234|50.25
john|520-452-9987|67.32
.....

I want it to look like this
 NAME | PHONE | AMOUNT|FILE_INSERTED
jane|520-234-1234|50.25|MY_FILE_20171101.txt
john|520-452-9987|67.32|MY_FILE_20171101.txt

How do I add this to my DATA FLOW TASK as a column to be inserted into the DB table?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Pawan KumarDatabase Expert
Awarded 2016
Top Expert 2016
Commented:
You have to alter your table and add a new column called "FILE_INSERTED"

Add a derived column called fileInserted , details you can get from https://mindmajix.com/ssis/how-to-use-derived-column-transformation-in-ssis-example
BI Consultant
Most Valuable Expert 2011
Commented:
This can be achieved quite easily actually, assuming that your Data Flow contains a Flat File Source component.  The Flat File Source component has a property called FileNameColumnName. At first sight this looks like a weird name for a property, until you find out what it's meant for.  If you give this property a value, for instance "Filename", the source component will add an extra column to the data flow with that given name.  The content of the new column is the name of your file being imported!
sqlagent007Technology professional

Author

Commented:
Thanks experts!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial