SSIS: variable expression using time in two places

2020-04-10 17:09发布

问题:

I have a variable expression that appends some date parts to use as a file name in two separate tasks.

But by the time the second task hits, the time has changed and the variable with it. Basically, I am creating a file in a folder for FTP exporting. But when teh FTP task goes to pick it up, it's 'not there' since the time has changed since the initial creation of the file and the FTP task trying to pick it up.

The flat file name and the FTP LocalPath are both using the variable 'FilePath' which is:

"C:\\WFSDEV_WSD_SHIP_FROM_STORE_" + (DT_WSTR,4)DATEPART("yyyy",GetDate()) + 
RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()) ,2) + 
RIGHT("0" + (DT_WSTR,2)DATEPART("dd",GetDate()),2) +
RIGHT("0" + (DT_WSTR,2)DATEPART("hh",GetDate()),2) +
RIGHT("0" + (DT_WSTR,2)DATEPART("mm",GetDate()),2) +
RIGHT("0" + (DT_WSTR,2)DATEPART()),2) +
".VD01"

Is there a way to set this var at the start of the package and use it from there unchanged?

回答1:

Don't use GETDATE() as it will be evaluated each time you inspect it.

Instead, pick a value that will be constant for the duration of the SSIS package but is updated when the package begins. My preference is @[System::StartTime] but some may prefer @[System::ContainerStartTime] The former is set when the package begins execution, the other is reset inside each container (ForEach Loop, etc)



标签: ssis