2009-03-17

SSIS : Dynamic Excel Destination File Name

In suitation that you may need to dump logs periodically, dynamic expression of SSIS could help you through this.
For example, by using the date as name to create a daily log from query.

A simple solution could be done by the 'isqlw -o' or 'sqlcmd -o' command with bat scripting. However, the log is only available in text format. To obtain an Excel log, you may use the following sample.

1.Open the BIDS and create a blank SSIS project.
2.select the SSIS export and import wizard under "Project Menu"
3.Follow the steps in the wizard with entering the exact data source and an arbitrary Excel destination.
4.After the creation of package, add a "package" variable (e.g. DirectoryPath) for storing the destination path and file name string. (View->Other window->Variables)
5.Select the "expression" in properties of the Excel destination connection.
6.Add an expression for the property "ExcelFileName"
@[User::DirectoryPath] + "\\" + (DT_WSTR,4)YEAR(GETDATE())
+ RIGHT("0" + (DT_WSTR,2)MONTH(GETDATE()), 2)
+ RIGHT("0" + (DT_WSTR,2)DAY(GETDATE()), 2) + ".xls"
7.When back to the properties listing. The ExcelFieldName was changed to date name style.
8.Turn the delayValidation property of the control flows and excel connection destination to false.
So to suppress the validation on non-existing file source.
9.Save, Deploy to SSMS job scheduler and Done!

The expression is provided from Zulfiqar.
http://zulfiqar.typepad.com/zulfiqars_web/2006/11/ssis_dynamic_fi.html
However, after adding the expression for the "Connection" property, the dtsx has became corrupted after run/reopen the project. By the way, The ExcelFileName was already fit enough for the purpose.

No comments:

Post a Comment