Search code examples
sql-serverssissql-server-2014

Use date in file name for csv-file created with Integration Services package


I create a package in integration services to extract data on a daily basis. Is there a way to add the date or date and time to file name to make it unique?

It needs to look like this CSV1-Delim-Elig-Date.cvs. The CSV1-Delim-Elig will always be part of the file name and will be saved as a .CVS


Solution

  • To dynamically generate file names you need to add an expression to the connection string property of the file connection manager.

    1. Select desired connection manager.
    2. In the properties pane click expressions. Then click on the ellipsis. enter image description here
    3. In the property column select ConnectionString from the drop down. enter image description here
    4. Click on the ellipsis in the expression column to bring up the expression editor. enter image description here
    5. Enter an expression to output your desired file name. Below is an example of your desired file name with the date appended.

    "C:\\Output\\CSV1-Delim-Elig-" + REPLACE((DT_WSTR, 50)(DT_DBDATE)GETDATE(),"-","") + ".csv"