Is it possible to override the value of a variable in a SSIS package, which is calculated via an expression, by passing in a different value on the DTExec command line?
I have a parameterized query and I'm passing variable User::StartDate
into it. The package name is OpenAirExport.dtsx.
If I invoke my package using DTExec from PowerShell I can set the StartDate variable fine on the command line. For example:
& "C:\Program Files\Microsoft SQL Server\150\DTS\Binn\DTExec.exe" -File 'OpenAirExport.dtsx' `
-Set '\Package.Variables[User::StartDate].Properties[Value];2020-09-22'
This works fine. I can see from the resulting data that the start date was indeed set to 22 Sep 2020.
99% of the time, though, the package will just be getting the previous day's data. So I set an expression on the StartDate variable to calculate its value:
DATEADD("day", DATEDIFF("day", (DT_DBTIMESTAMP)0, GETDATE()) - 1, (DT_DBTIMESTAMP)0)
(This rather complicated looking expression just counts the number of days since day 0 then adds them to day 0 and subtracts 1. This is a fairly standard way in SQL Server of stripping the time from a datetime, leaving just the date. In this case it will give a datetime of 00:00 hours yesterday)
Now if I call the package using DTExec from PowerShell without setting the StartDate variable value it gives the correct result - data from yesterday.
Every now and again a downstream process fails and we're asked to re-run a previous day's data. So I want to be able to override the calculated value for StartDate with a value passed in from the command line. But I find that if I try to set the value from the command line this value gets ignored and the expression is still used to calculate StartDate.
Is there any way I can force SSIS to override the expression value with a value passed in from the command line?