简体   繁体   English

SSIS:条件拆分结果为变量

[英]SSIS: Conditional Split result to variable

I have condition where I need to feed conditional split result based on condition (will be just one int value) to variable. 我有条件,我需要根据条件(将只是一个int值)提供条件拆分结果给变量。 Can some one help how to do this? 有人可以帮忙吗?

My actual package (Data flow): 我的实际包装(数据流):

XML Source --> Conditional split (based on condition) 2 outputs..one result based on condition (will be just one int value) need to pass it on to variable. XML Source > Conditional split (基于条件)2个输出..一个基于条件的结果(将只是一个int值)需要将其传递给变量。 How to achieve this? 如何实现呢?

纯SSIS方式-将数据流消耗到Recordset目标中 ,然后使用ForEach循环遍历它,将值分配给所需的变量。

you have to use a script component to achieve this: 您必须使用脚本组件来实现此目的:

  • Create a script component ( Choose it's type as Destination ) 创建一个脚本组件( 选择它的类型作为Destination

在此处输入图片说明

  • Double click on script component and Choose your Variable as a ReadWrite Variable. 双击脚本组件,然后选择您的变量作为ReadWrite变量。 ( in my example the variable is named Result 在我的示例中,变量名为Result

在此处输入图片说明

  • Inside the script window write the following code 在脚本窗口内编写以下代码

     Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer) If Not Row.inColumn_IsNull Then Variables.Result = Row.inColumn End If End Sub 

Side Note: Variable value does not change before dataflowtask execution is finish, to use the new value you have to continue your work in another dataflowtask 旁注:变量值在dataflowtask执行完成之前不会更改,要使用新值,您必须在另一个dataflowtask继续工作

I know two ways to realize this. 我知道两种方法可以实现这一目标。

First: Do it with a C# script component, this is the easiest way. 第一:使用C#脚本组件完成此操作,这是最简单的方法。 Just put a script component behind your conditional split, select your variable as "ReadWrite", then set it like that in the code: 只需将脚本组件放在条件拆分的后面,将变量选择为“ ReadWrite”,然后像在代码中那样进行设置:

Dts.Variables["yourvariable"].Value = Input0Buffer.Yourcolumn

I don't have access to SSIS right now, so I can't give you the exact code, but this should get you started. 我现在没有访问SSIS的权限,所以我无法给您确切的代码,但这应该可以帮助您入门。

Second: Write to a table and read it back with Execute SQL task. 第二:写入表并通过Execute SQL任务将其读回。 I don't really like this way ;-) 我不太喜欢这种方式;-)

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

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