SSIS Design Technique: Using a Dummy Script Task to Enable Conditional Top-Level Tasks
Here's a SQL2K5 Integration Services control-of-flow design quandry I've encountered more than once: I have a task (any task, say for instance an FTP task) that I want to execute conditionally, but it does not have a direct parent task. For example, my hypothetical FTP task could be the first task inside of a sequence container, and as such has no direct parent. Since you can't have a precedence constraint (as far as I know) between a container and one of it's children, you're stuck without a place to put an expression to control whether your conditional task should execute.
One solution I tried using an Expression attached to the Disable property, but the problem I ran into there is that expressions are evaluated, as far as I can tell from the documentation, when the task is validated. The particular task I tried this on was inside of a Foreach container, and it appeared that the expression was being evaluated before my Foreach-related variable was being initialized. Maybe in a different circumstance the trick of attaching an expression to Disable would have worked...
So I came up with a little trick that has worked well: I added a Script task, did not add any code to it, and called it scrDummy. Basically, this sets up a situation where the Script task will always execute, always succeed, and do absolutely nothing. Then I made a precedence constraint from scrDummy to my conditional task, which in this case was an FTP task. Then I attached an expression to the precedence constraint, and everything worked great because not only do I have a home for my expression, the expression is evaluated at execution time and not validation time.
See also "Sequence Container as Indirection Mechanism to Enable Flow," which describes another SSIS design pattern I have used in conjunction with this pattern.
Comments welcome.
Dan


expression is evaluated at execution time not validation time
Thanks. I was going crazy with why my original expression on the task was "not working"