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

℡╲_俬逩灬. 提交于 2019-12-10 19:26:05

问题


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.


回答1:


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, i.e. use !=, for the @[User::gempar] variable.

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


来源:https://stackoverflow.com/questions/54444406/how-to-use-the-result-set-from-a-query-in-the-constraint-editor-to-conditionally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!