简体   繁体   中英

How to use the Result Set from a Query in the Constraint Editor to conditionally execute SQL Task?

My SQL Script is storing in @gempar = NULL and in @beneficiary = '2018-01-01' . In need to Execute the next Execute SQL Tasks based on the content of those variables. IF ISNULL(@gempar) = True then we don't run the following task (because then @gempar is equal to NULL ). On the other hand, IF ISNULL(@beneficiary) = False then we run the following task (because @beneficiary is not NULL ).

在此输入图像描述

The next image is the Result Set from the Execute SQL Task:

在此输入图像描述

I created the 2 variables beneficiary and gempar in SSIS but I am not sure if they should be written as following in the expression column: @[User::gempar] and @[User::beneficiary] or as they are now on the next image:

在此输入图像描述

This is the SSIS Control Flow:

在此输入图像描述

The Precedence Constraint Editor 's Output should be True. Why is it not catching the value in @beneficiary ?

在此输入图像描述

I expect the TRUNCATE GEMPAR TABLES task to stop and the TRUNCATE BENE TABLES task to continue.

SSIS doesn't allow for SSIS variables to be null. It's somewhat older and in a slightly different context, but this article further details SSIS variables in regards to null. Since the variables you're using are of the string data type, an option compare the variable to a blank string. Keep in mind, that this does not guarantee these variables were null as a result of what was performed in the Execute SQL Task. You may need to substitute blank strings or another value in your SELECT statement for this. For example, COALESCE(@beneficiary , '') .

Right-click the Precedence Constraint between the tasks select Edit. Then change the Evaluation Operation to Expression and add an expression as follows. Depending on your expected outcome, the Evaluation Operation may need to be changed to Expression and Constraint , with the status of the prior task set in the Value field. The example below returns true when the @[User::beneficiary] variable is null, which will allow the following task to execute as you described. You can reverse this, ie use != , for the @[User::gempar] variable.

@[User::beneficiary]) == ""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM