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:
 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?
LVL 1
sqlagent007Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Pawan KumarDatabase 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 https://mindmajix.com/ssis/how-to-use-derived-column-transformation-in-ssis-example
0
ValentinoVBI 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!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sqlagent007Author Commented:
Thanks experts!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.