如何处理数据流任务上的空查询结果?

发布于 2024-12-25 01:32:37 字数 98 浏览 3 评论 0原文

我在 Foreach 循环内使用数据流迭代了几年,但有些年不会返回任何数据,因此它们 SSIS 包失败,有没有办法处理这个问题?告诉包忽略这些空白并继续执行?

谢谢,

I'm iterating several years with a Dataflow inside a Foreach Loop, but there are some years that will not return any data, therefore they SSIS package fails, is there a way to handle this? To tell the package to ignore those blanks and keep executing?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云仙小弟 2025-01-01 01:32:37

如果您不想改变数据传递到 Foreach 组件的方式,可以采取的一种方法是:

  1. 您可以包含一个额外的执行 SQL 任务 组件在 Foreach 容器内,首先检查是否有任何数据要处理。

  2. 创建一个变量,您的 SQL 任务将为其设置记录计数,例如 @cntProceed

  3. 设置此组件在您的数据流任务之前运行。

  4. 修改优先级约束(从 SQL 任务到数据流任务的绿色箭头)。将求值操作设置为表达式和约束,将Value设置为Success,将Expression设置为表达式 to @cntProceed != 0

这一切的作用是:在 foreach 组件/容器内,它将首先检查是否存在任何可以使用的数据。这就是附加组件将要做的事情,如果有数据要使用,它将继续到数据流组件。否则,“each”(或者更确切地说......那个循环)将结束,并且Foreach将移至下一个。

One approach you can take if you don't want to touch how the data is being passed to the Foreach component:

  1. You may include an additional Execute SQL Task component inside the Foreach container that checks first if there is any data to process.

  2. Create a variable to which your SQL task will set the record count to, for example @cntProceed

  3. Set this component to run before your Dataflow task.

  4. Modify the precedence constraint (green arrow from your SQL task to your Dataflow task). Set the evaluation operation to Expression and Constraint, Value to Success, and Expression to @cntProceed != 0

What this all does: Inside the foreach component/container it will first check if there exists any data to work with. That's what the additional component will do, and if there's data to use, it will proceed to the dataflow component. Otherwise, that "each" (or rather.. that one loop) will end and the Foreach will move to the next.

2025-01-01 01:32:37

我不确定如果查询返回 0 行,为什么数据流会失败。一种可能的解决方案是询问有效年份的数据,并且仅迭代有效年份。这可以通过以下方式完成:

  1. 在 ForEach 循环容器之前创建执行 SQL 任务
  2. 将执行 SQL 任务的结果集设置为完整行
  3. 将结果集选项卡设置为对象变量
  4. 将 ForEach 循环容器设置为 ForEach ADO 枚举器
  5. 设置 ADO 对象源变量到对象变量
  6. 将变量映射设置为年份变量
  7. 将年份作为参数传递给数据流。

您可以查看包装上的代码并将其发布吗?我很高兴看看是否可以重复您遇到的问题,并为您提供更直接满足您发布的需求的解决方案。

I'm not sure why a data flow would fail if a query returns 0 rows. One possible solution is to interrogate your data for the valid years and only iterate through valid years. This could be done by:

  1. Create an Execute SQL task before the ForEach Loop container
  2. Set the ResultSet to full rows for the Execute SQL task
  3. Set the Result Set tab to an object variable
  4. Set the ForEach Loop container to a ForEach ADO Enumerator
  5. Set the ADO object source variable to the object variable
  6. Set the Variable Mappings to a variable for the year
  7. Pass the year as a parameter to the data flow.

Can you View Code on the package and post that? I'd be happy to see if I can duplicate the problem you are experiencing and give you a solution that more directly meets your posted need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文