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

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?
Who is Participating?
ValentinoVConnect With a Mentor BI ConsultantCommented:
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!
Pawan KumarConnect With a Mentor Database ExpertCommented:
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
sqlagent007Author Commented:
Thanks experts!!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.