[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3992
  • Last Modified:

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?

3 Solutions
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.
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 .

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now