gpt4 book ai didi

sql-server - 在SSIS中显示foreach循环迭代次数

转载 作者:行者123 更新时间:2023-12-03 02:38:10 25 4
gpt4 key购买 nike

我需要检查在 Visual Studio 2017 中运行的 foreach 循环容器任务的迭代次数。如何实现此目的?

最佳答案

(1) 使用表达式任务计算迭代次数

SSIS 2012+ 中可用的任务

在 Foreach 循环容器中,there is no properties that contains the iteration number 。您可以通过创建 Int 类型的 SSIS 变量(初始值等于 0)来实现此目的。示例 @[User::Counter]

在 Foreach 循环容器内,添加具有以下表达式的Expression Task:

@[User::Counter] = @[User::Counter] + 1

有用的链接

(2) 使用脚本任务计算迭代次数

您可以使用脚本任务实现相同的过程,方法是创建计数器变量,在脚本任务中将其选择为读写变量,然后在脚本内将类似的行添加到主函数中:

Dts.Variables["User::Counter"].Value = Convert.ToInt32(Dts.Variables["User::Counter"].Value) + 1;

引用文献

显示数据

显示数据的方式有多种。一种是使用脚本任务。指定您的 @[User::Counter] 变量位于 ReadOnly 集合中,然后将值发送到运行日志中

    public void Main()
{
bool fireAgain = false;
string message = "{0}::{1} : {2}";
foreach (var item in Dts.Variables)
{
Dts.Events.FireInformation(0, "SCR Echo Back", string.Format(message, item.Namespace, item.Name, item.Value), string.Empty, 0, ref fireAgain);
}

Dts.TaskResult = (int)ScriptResults.Success;
}

另一种方法是通过表达式设置 Foreach 循环中任务的 Name 属性。右键单击循环中的任务并选择属性。在“属性”部分中找到 [+]Expressions 集合,然后单击右侧省略号 ...,然后在新窗口中选择左侧的“名称”并设置右侧表达式为

"My Task " + RIGHT("000" + (DT_WSTR,3) @[User::Counter], 3)

这会连接两个字符串“My Task”,并将 Counter 变量转换为字符串,并在左侧用零填充,因此它始终是 3 位数字

关于sql-server - 在SSIS中显示foreach循环迭代次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54717639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com