My colleague Peter asked about embedding a date in the filename of an SSIS output. I gave him some general guiance about a couple of strategies, which he used to find this StackOverflow article(http://stackoverflow.com/questions/4372009/add-datestamp-to-a-txt-file-in-an-ssis-package) on the topic. The general idea is to use an expression in the connection's expressions like this:
"filename_" + RIGHT("0" + (DT_STR, 2, 1252) (DATEPART("mm", GETDATE())), 2) + RIGHT("0" + (DT_STR, 2, 1252) (DATEPART("dd", GETDATE())), 2) + (DT_STR, 4, 1252) (DATEPART("yyyy", GETDATE())) + ".txt"
You can easily modify the above example to rearrange the various components to your needs, however us technical types often look at a format like YYYY-MM-DD, zero padded on month and day, of course, as a natural solution because sort alphabetically also sorts by date. You might also need to do that without dashes, so why not use a format that comes that way and remove the dashes?
"filename_" + Replace(Substring((DT_WSTR, 50) GetDate(), 1, 10), "-", "") + ".txt"
I think the answer will be in localization settings for other regions, but if you're using a typical US installation, this will give you a nice sortable output.
No comments:
Post a Comment