Using Constraints and Expressions

Besides the regular Success and Failure constraints, you can create precedence constraints that are linked to an expression.

In this example, I have a Script Task that determines the course for the workflow.

Besides the pass and fail, I also want to handle a third case that will be executed whenever a special condition is met in the Script Task.

To set this up, I create a new Boolean variable (varSpecialCase), and set the value in my Script Task. Double clicking the “Handle Special Case” constraint brings up the Precedence Constraint Editor, where I can change the way the constraint is evaluated.

Here I’ve set “Evaluation operation” to “Expression”, and used my variable in the expression text. If varSpecialCase has been set to true by the Script Task, the “Handle Special Case” script task will be executed.

One thing to keep in mind:  =   !=   ==

(The equals sign is not the same as double equals in the constraint expression!)

I had originally set my expression up using a single equal sign.

As this is still a valid expression, it will validate successfully when you click the Test button.

When you run however, it always fails. After spending a while trying to figure out why my task wasn’t being executed, I finally looked it up the operators in the Integration Services Expression Reference. I’ll definitely look there first, next time!


Comments (8)

  1. Michael says:

    So will "Handle Success" also run as well as "Handle Special Case" ?  If so, how do you create a basic "If x then blah, else blah" type construct?

  2. mmasson says:

    You'd do it with two separate precedence constraints – one with the "if" expression, and one with the "else".

  3. Emil Glownia says:

    Hi Matt,

    I hope you don't mind if I share a link to SSIS 2012 Precedence Constraint Video Tutorial that covers most aspects of Precedence Constraint in 6 videos.

    Here's the link

    Take care


  4. SimpleSQL says:

    When selecting only Expression for the Evaluation operation, the Value becomes greyed out suggesting that it is not applicable, however it must be set to Completion otherwise the task will fail.

  5. Kael Dowdy says:

    One thing to keep in mind:  =   !=   ==

    (The equals sign is not the same as double equals in the constraint expression!)


    Exactly what I was looking for — thanks!

  6. Andy Reed says:

    Brilliant on the ==

    Not obvious at all  🙂

  7. jeremy says:

    To make it even simpler, if you are evaluating a boolean to see if it is true, you don't need anything besides the variable name.