Create dynamic file name for flat file destination

I want to create a file name for each day that contains a date in my flat file destination with SSIS on MS SQL 2008. Something like 09192012_filename.txt. I want the file to be named dynamically each day.

Can someone walk me through this?

Who is Participating?
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.

Saurabh BhadauriaCommented:
First create a flat file connection .  then open property of that connection , now in property tab go to EXPRESSIONS a grid page will be open . List down all the properties and select connection string.
Now you click on brows button under expression column and create your custom expression for connection string.

chk below link for details.
In the properties of the flat file connection manager (for your flat file destination),
create an expression for the Connection String.

The basic syntax of your expression will be:
"C:\\Documents and Settings\\Me\\Desktop\\" +
(DT_WSTR, 2)month(getdate())  +  (DT_WSTR, 2)day(getdate()) +  (DT_WSTR, 4)year(getdate()) + "_filename.txt"

Open in new window

This would create the file "09192012_filename.txt" on (my) desktop.

Note the escaped backslashes in the directory path. Don't forget them.

It isn't necessary, but it's a good practice to store the directory path and file naming convention in user variables and then just use the variables to create the connection string.

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
To create a dynamic  file name for flat file connection  :

1) Create a flat file connection in connection manager.
2) open  flat file connection properties.
3) Save flat file name in variable .
4) select Expressions in properties and select connection manager and create a dynamic connection as shown in attached file .
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 2008

From novice to tech pro — start learning today.