September 7, 2016 at 6:24 am
I apologize if this question has been already asked and answered, but I have yet to find a good solution for this. I have a monthly SSIS job that sends formatted data out of one of our SQL database tables and into a simple csv file. The receiving company now needs that file to have the DATE of the operation in the file name (and not a static file name like before). Is there a way in the SSIS job to rename the destination csv filename?
Thanks for the information.
September 7, 2016 at 6:34 am
It's probably easier to leave the destination file name as is and add a subsequent task to do a copy/rename.
If you do a search on SSIS file system task rename file with date or something akin, you should find examples all over the place.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
September 7, 2016 at 6:41 am
Thanks and that is the direction I was just looking at, using the File System Task to manipulate that filename after the processing was done. I just now need to see how to use that control and I will search just as you advised.
September 7, 2016 at 6:51 am
Or if you are happy writing some C# and using a Script Task (my preference), it takes only three or four lines of code. I can provide an example if you are interested.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
September 7, 2016 at 6:59 am
You could also just write an expression on the flat file connection manager.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
September 7, 2016 at 7:20 am
Thanks, that would be great too as in this project I am not using C#, but I easily could.
September 7, 2016 at 7:25 am
Is it as simple as doing this: System.IO.File.Move(@"C:\From.txt", @"C:\TO.txt"); ?
Except I need the "TO.txt" file to be YYYYMMDD.csv
September 7, 2016 at 7:29 am
Brad Allison (9/7/2016)
Is it as simple as doing this: System.IO.File.Move(@"C:\From.txt", @"C:\TO.txt"); ?Except I need the "TO.txt" file to be YYYYMMDD.csv
Yes, but be aware that the Move method cannot do an overwrite.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
September 7, 2016 at 7:34 am
In this use case we would not need to do an overwrite (not that I am aware of yet). This is a file that will be run once a month, at the beginning of the month, and then FTP over to the requestor's server.
September 7, 2016 at 8:05 am
Koen Verbeeck (9/7/2016)
You could also just write an expression on the flat file connection manager.
This is how I normally do it.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
September 7, 2016 at 8:10 am
Koen Verbeeck (9/7/2016)
Brad Allison (9/7/2016)
Is it as simple as doing this: System.IO.File.Move(@"C:\From.txt", @"C:\TO.txt"); ?Except I need the "TO.txt" file to be YYYYMMDD.csv
Yes, but be aware that the Move method cannot do an overwrite.
So what happens when the job runs next month?
I suggest adding "using System.IO;" in your Namespaces section, so that you can make your code a bit more snappy (File.Move rather than System.IO.File.Move ...).
If you want to bullet-proof your code a little, add a section to delete the target file if it exists, before doing the File.Move. Something like this:
if (File.Exists(targetFilePath))
{
File.Delete(targetFilePath);
}
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
September 7, 2016 at 8:14 am
I guess I don't understand, but each month it runs, it would be a unique file name. So next month it should be something like 20161001.csv. In November it will be 20161101.csv, right? So I shouldn't have that issue of the same filename. I know though that it is better to be safe then sorry
September 7, 2016 at 8:26 am
Brad Allison (9/7/2016)
I guess I don't understand, but each month it runs, it would be a unique file name. So next month it should be something like 20161001.csv. In November it will be 20161101.csv, right? So I shouldn't have that issue of the same filename. I know though that it is better to be safe then sorry
Yes of course, my earlier comment was off the mark. But what if the job fails one day and has to be rerun?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply