Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Server SSIS package Flat File Destination file name pattern (date, time or similar)?

I'm scheduling a SSIS package for exporting data to flat file.

But i want to generate file names with some date information, such as foo_20140606.csv

Is it possible?

Thanks

like image 236
ʞᴉɯ Avatar asked Jun 27 '14 13:06

ʞᴉɯ


1 Answers

With the help of expressions you can make connection dynamic.

Select your flat file connection from Connection Managers pane. In Properties pane, click on Expression(...). Then choose ConnectionString Property from drop down list and in Expression(...) put your expression and evaluate it.

Expression build -

For day : (DT_STR,4,1252)DAY( DATEADD( "dd", -1, getdate() ))
For month: (DT_STR,4,1252)MONTH( DATEADD( "dd", -1, getdate() ))
For Year:  (DT_STR,4,1252)YEAR( DATEADD( "dd", -1, getdate() ))

Example expression(you need to tweak as per your requirement) -

"E:\\Backup\\EmployeeCount_"+(DT_STR,4,1252)DATEPART( "yyyy" , getdate() ) + RIGHT("0" + (DT_STR,4,1252)DATEPART( "mm" , getdate() ), 2) + RIGHT("0" + (DT_STR,4,1252)DATEPART( "dd" , getdate() ), 2) +".txt" 

which is giving E:\Backup\EmployeeCount_20140627.txt as value.

Please note - You need a working flat file connection so first create flat file connection whose connectionString property is then going to be replaced automatically by expression.

You can follow these step by step articles as well.

ssis dynamically naming destination

SSIS Dynamic Flat File Connection

enter image description here

enter image description here

like image 76
Vikramsinh Shinde Avatar answered Sep 17 '22 01:09

Vikramsinh Shinde