ssisconditional-statementscontrol-flow

Controlling the flow in SSIS package based on a condition


Is there a way to conditionally (through a script task or anything else), control the flow of program in SSIS?

Currently I have a package that would create 5 different excel sheets (through Execute SQL Task) dynamically. There maybe times when all 5 will have data or only 1 may have data. When its just 1 that has data, it is fine. But the real problem arises when there are 5 DFT's that are trying to write the data simultaneously to the same workbook (albeit different sheets inside that). The package fails with an OLEDB error.

After a lot of head breaking, I finally figured out that it was a concurrency control issue that wasn't allowing me to write to the excel file simultaneously. To further my solution, I used expressions on precedence constraints to control if the sheets get created or not. But the real trouble is that after creating the sheets, the package would fail trying to write data to 2 different sheets simultaneously.

Is there a way, I can assign an 'Execution Order' for the DFT's? This is the reason I am looking for a script task so that when a particular sheet's count is 0 then it does no work and the control moves to another branch.

I hope I have not confused you here. But if I have, I'll be glad to provide more details on this question. Thanks for reading.


Solution

  • My first thought is to have a bunch of sequence containers, one per possible Excel sheet, each of which holds three tasks:

    1. A script task to figure out whether or not to create the sheet, and set a boolean package variable accordingly
    2. An SQL task to create the worksheet
    3. A data flow task to populate the worksheet

    The precedence constraint between tasks 1 and 2 would be an expression of the boolean being true:

    screenshot of precedence constraint editor showing expression of @DoNorthRegion

    The precedence constraint between tasks 2 and 3 would be a success constraint, as would the precedence constraints between the sequence containers. Overall, it would look like this:

    screenshot of four sequence containers, one expanded to show contents