There are a few different ways to solve this.
First approach
The first way is through an Expression on each of your Sequence Containers. The Expressions will control the Disable state of the container and the expression you are looking for is DATEPART for a Weekday dw
Is it Sunday?
DATEPART("weekday", getdate()) == 1
Is it not Sunday?
DATEPART("weekday", getdate()) != 1
Next approach
The problem with using the getdate approach is testing - how are you going to test all the possible scenarios? Are you going to change the clock on the computer to verify the Sunday/nonSunday branch works?
I would create an SSIS Variable called CurrentDate
of type DateTime and initialize it to today.
I would create a second SSIS Variable called IsSunday
of type Boolean and set an expression on this variable to be DATEPART("weekday", @[User::CurrentDate] ) == 1
I would then modify my two Sequence Containers to have a new, simplified expression on their Disabled state
Is it Sunday
@[User::IsSunday]
Is it not Sunday
!@[User::IsSunday]
Run the package and verify the non-Sunday branch lights up (today is Thursday). Stop execution and then change the value of @[User::CurrentDate] to last Sunday (2019-11-17) and restart the package. Verify the Sunday branch lights up and then stop execution.
Now that you have the logic sound, the remaining step is to modify the SSIS Variable CurrentDate to have an expression on it of getdate()
. Restart the package and verify the non-Sunday branch has once again lit up for execution.
Next, Next approach
Congratulations, your package is implemented and it runs well. Until it doesn't. The server maintenance window runs long and this package doesn't actually start until Monday morning at 12:15 a.m. How are the operators going to be able to tell the package "Run the Sunday logic?" You aren't, unless you edit the package and nobody wants to do that.
In this situation, I could use the basic construct I've built above but now, I would add a Parameter to the package, of type Boolean and call it something like ForceSunday
and the default value is False. Only in situations where I need to force the Sunday logic would that be flipped to True (and only for the one run-time, not a design-time change).
The logic for our IsSunday gets a touch more complicated as we need to OR ||
the logic for the parameter name.
DATEPART("weekday", getdate()) == 1 || @[$MyPackage::ForceSunday]
I think I have the parameter name syntax correct but the dollar sign could be elsewhere (this is all from memory)
Next, Next, Next approach
This is a really complex package. Make life easier for everyone - Copy & paste into a package that has Sunday logic and one that has Non-Sunday logic.
Final notes
Regardless of the approach you take, the next problem you will run into is the precedence constraint between both of these containers feeding into the container on the right of the screen. The solid green line is a precedence constraint of Success
and Logical AND
- so the final box will only ever start if both the Sunday and non-Sunday workflows execute. Logically, that can't happen so you need to double click the line and change it to a Logical OR
2 Data Flow Tasks Linking to one Execute SQL Task