Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


to rename a file by attaching datestamp at the end of filename using SSIS File task


to rename a file by attaching datestamp at the end of filename using SSIS File task

Author
Message
jbrannon
jbrannon
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 88
How would I get the previous month?

I need my file to be renamed Mods201001.xls.

Here's what I have

@[User::SharePath] +
RIGHT("0" + (DT_STR,4,1252) DatePart("yyyy",getdate()),4)+
RIGHT("0" + (DT_STR,4,1252) DatePart("m", getdate())-1,2)

But I get an error -
Attempt to set the result type of binary operation ""0" + (DT_STR4,1252)DatePart("m",GETDATE))-1" failed with error code 0xC0047081
jbrannon
jbrannon
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 88
Tommy -

I've also tried your solution but I'm getting the red x in the script task.

The task is configured to pre-compile the script, but binary code is not found. Please visit the IDE in Script Task Editor by clicking Design Script button to cause binary code to be generated.

I copied your code and put in my file name and file path but I get that error, any ideas on the cause?

Thanks
mc 22238
mc 22238
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 18
I wish to strip the date from a filename that is generated from another system so that I can run a schedule DTSX packages on the file. The file is in the format SampleFile_<yyyymmdd> <hhmmss>.csv. I'd like to back this up to another folder but also rename it to a static value such as SampleFile_Current.csv so that my DTSX package can run as it depends on the filename.

Any suggestions welcome.

thanks
MC
dg227
dg227
SSC Veteran
SSC Veteran (268 reputation)SSC Veteran (268 reputation)SSC Veteran (268 reputation)SSC Veteran (268 reputation)SSC Veteran (268 reputation)SSC Veteran (268 reputation)SSC Veteran (268 reputation)SSC Veteran (268 reputation)

Group: General Forum Members
Points: 268 Visits: 808
One thing to keep in mind is that breakpoints will cause that expression-based variable to be re-evaluated at the time that you step past the break point. If you need to reference that same value (in this example, if you add an expression-derived variable in the name of a file before the break point and then the variable-named file name is again used in a later/subsequent task after the break point) could potentially be different because of that re-evaluation.

Granted you'll probably only see this if you include seconds as part of the stamp, but if the before/after time of the break point spans over a minute change (or going past midnight, impacting the date, also), the variable will be re-evaluated and change.

A safer, more static approach it to set variable in a script task in the control flow, which keeps that value constant throughout the package or container (until you perhaps re-run that task in a loop).
ged.burnett
ged.burnett
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 67
Hi Adam, this is brillient, just what I was looking for too...well, almost.

I just need to put a small spanner in the works. What is the best way to give the file name yesterday's date? I have tried fitting "DATEADD(m, - 1, { fn CURDATE() })" into your script but it aint having it. Any ideas?

Regards,

Ged
jamestux
jamestux
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 1
Hello - I just created an account so that I could thank Adam and Tommy for this thread - I adapted the code to put hours minutes and seconds in too but other than that it was just what I was looking for (when I found how to edit the connection string expression in VS2008!)

Thank you Smile

James
GLIC DBA
GLIC DBA
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 164
Adam,

Thanks for the nice streamlined solution. Works like a charm.
greg.ellis
greg.ellis
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 25
I am trying to accomplish basically the same thing, but am having big issues with it:

using SQL 2005 to run SSIS and export file name myfile_.csv and placing it in folder on the same server "c:\apps\SalesExport\myfile.csv

This works great, but now I either need to rename the file on the way out or after the fact to add datetime stamp like myfile_031303291245.csv. I am lost, been working on this for several days, any help would be great, thanks
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search