在 SSIS 中,如何获取从应该处理的源返回的行数

2021-12-30 00:00:00 events rows event-handling sql-server ssis

我正在开展一个项目,将日志记录添加到我们的 SSIS 包中.我正在通过实现一些事件处理程序来做我自己的自定义日志记录.我已经实现了 OnInformation 事件以将时间、源名称和消息写入日志文件.当数据从一个表移动到另一个表时,OnInformation 事件会给我一条消息,例如:

I am working on a project to add logging to our SSIS packages. I am doing my own custom logging by implementing some of the event handlers. I have implemented the OnInformation event to write the time, source name, and message to the log file. When data is moved from one table to another, the OnInformation event will give me a message such as:

组件TABLENAME"(1)"写入了 87 行.

component "TABLENAME" (1)" wrote 87 rows.

如果其中一行失败,假设只有 85 行被处理,而预期的 87 行我会假设上面的行会读取 wote 85 行.在这种情况下,如何跟踪应该处理多少行?我希望看到类似 wote 85 of 87 rows 的内容.基本上,我想我需要知道如何获取从源查询返回的行数.有没有简单的方法可以做到这一点?

In the event that one of the rows fails, and lets say only 85 rows were processed out of the expected 87. I would assume that the above line would read wrote 85 rows. How do I track how many rows SHOULD HAVE processed in this case? I would like to see something like wrote 85 of 87 rows. Basically, I think I need to know how to get the number of rows returned from the Source's query. Is there an easy way to do this?

谢谢

推荐答案

你可以在Data source之后使用Row Count transaformation并将其保存为变量.这将是要处理的行数.一旦它被加载到目标中,你应该使用 Control flow 中的 Execute SQL Task 并使用 Select Count(*) from <<>; 并将计数保存到其他变量中[您应该在查询中使用 Where 子句来识别当前负载].因此,您将处理用于记录的行数.

You can use the Row Count transaformation after the Data source and save it the variable. This is going to be number of rows to be processed. Once it got loaded into the Destination, you should use the Execute SQL Task in Control flow and use Select Count(*) from <<DestinationTable>> and save the count into the Other variable[You should use the Where clause in your query to identify the current load]. So you will have number rows processed for logging.

希望这有帮助!

相关文章