Create dynamic file name for flat file destination

Posted on 2012-09-19
Last Modified: 2012-09-20
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?

Question by:earwig75
    LVL 12

    Assisted Solution

    by:Saurabh Bhadauria
    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.
    LVL 12

    Accepted Solution

    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.

    Assisted Solution

    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 .

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now