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

sqlagent007 used Ask the Experts™
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:

I want it to look like this

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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Pawan KumarDatabase Expert
Awarded 2016
Top Expert 2016
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
BI Consultant
Most Valuable Expert 2011
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


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