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?
Jared_SConnect With a Mentor Commented:
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.
Saurabh BhadauriaConnect With a Mentor Commented:
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.
kapilkhalasConnect With a Mentor Commented:
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 .
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.