简体   繁体   English

如何使用约束编辑器中的查询结果集来有条件地执行SQ​​L任务?

[英]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' . 我的SQL脚本存储在@gempar = NULL@beneficiary = '2018-01-01' @beneficiary '2018-01-01' In need to Execute the next Execute SQL Tasks based on the content of those variables. 需要根据这些变量的内容执行下一个执行SQL任务。 IF ISNULL(@gempar) = True then we don't run the following task (because then @gempar is equal to NULL ). IF ISNULL(@gempar) = True然后我们不运行以下任务(因为那时@gempar 等于NULL )。 On the other hand, IF ISNULL(@beneficiary) = False then we run the following task (because @beneficiary is not NULL ). 另一方面,IF ISNULL(@beneficiary) = False然后我们运行以下任务(因为@beneficiary 不是NULL )。

在此输入图像描述

The next image is the Result Set from the Execute SQL Task: 下一个图像是执行SQL任务的结果集

在此输入图像描述

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: 我在SSIS中创建了2个变量faviciary和gempar但是我不确定它们是否应该在表达式列中编写如下: @[User::gempar]@[User::beneficiary]或者它们现在在下一个图片:

在此输入图像描述

This is the SSIS Control Flow: 这是SSIS控制流程:

在此输入图像描述

The Precedence Constraint Editor 's Output should be True. 优先约束编辑器的输出应为True。 Why is it not catching the value in @beneficiary ? 为什么它没有抓住@beneficiary的价值?

在此输入图像描述

I expect the TRUNCATE GEMPAR TABLES task to stop and the TRUNCATE BENE TABLES task to continue. 我希望TRUNCATE GEMPAR TABLES任务停止并且TRUNCATE BENE TABLES任务继续。

SSIS doesn't allow for SSIS variables to be null. SSIS不允许SSIS变量为空。 It's somewhat older and in a slightly different context, but this article further details SSIS variables in regards to null. 它有点旧,并且在稍微不同的上下文中,但本文进一步详细介绍了关于null的SSIS变量。 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. 请记住,这并不能保证这些变量因执行SQL任务中执行的操作而为空。 You may need to substitute blank strings or another value in your SELECT statement for this. 您可能需要在SELECT语句中替换空字符串或其他值。 For example, COALESCE(@beneficiary , '') . 例如, 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. @[User::beneficiary]变量为null时,以下示例返回true,这将允许执行以下任务,如您所述。 You can reverse this, ie use != , for the @[User::gempar] variable. 您可以对@[User::gempar]变量进行反转,即使用!=

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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