简体   繁体   English

记录通过SSIS执行任务更新的行

[英]Record rows updated through SSIS execute task

I have a package which connects to SourceDB1 and execute an update statement that updates DestDB2. 我有一个连接到SourceDB1并执行更新DestDB2的更新语句的程序包。 Now I have many such source DB and destination DB which has the similar structure. 现在,我有许多这样的源DB和目标DB具有相似的结构。 For this I have for each loop container within which the execute SQL task is placed. 为此,我为每个循环容器放置了执行SQL任务。 Now, since the sourceDB connection varies , I have created a variable named SourceConnString . 现在,由于sourceDB的连接有所不同,因此我创建了一个名为SourceConnString的变量。 Likewise, the update query is also within a variable named UpdateVariable . 同样,更新查询也位于名为UpdateVariable的变量内。 I created UpdateVariable because source and destination are two different databases. 我创建UpdateVariable原因是源和目标是两个不同的数据库。

Now I need to save the number of records that are updated in the execute sql task each time. 现在,我需要保存每次在exec sql任务中更新的记录数。 The records count should be inserted into a table or flat file whichever is easy. 记录计数应插入到表或平面文件中,以较容易的方式为准。

I saw tutorials how to do this without using an update through variable. 我看到了教程,该如何不使用变量更新来做到这一点。 Is there any way we could return the count of rows in my situation. 在我的情况下,有什么方法可以返回行数。

You can use a Select query with @@ROWCOUNT after the UPDATE query, like the following: 您可以在UPDATE查询之后对@@ROWCOUNT使用Select查询,如下所示:

UPDATE SomeTable Set SomeColumn = SomeValue;

SELECT @@RowCount as NumberOfAffectedRecords

And use a Single Row ResultSet to get the value. 并使用Single Row ResultSet来获取值。

The following article contains a Step-by-step tutorial 下一篇文章包含分步教程

You can use ExecValueVariable property, in Execute SQL Task it stores number of records affected by SQL command. 您可以使用ExecValueVariable属性,在“执行SQL任务”中存储受SQL命令影响的记录数。 You have to specify variable name at ExecValueVariable property or pick it up from drop-down as shown below. 您必须在ExecValueVariable属性中指定变量名称,或从下拉菜单中进行选择,如下所示。 在此处输入图片说明

I did the following. 我做了以下。 A new variable “ Newupquery ” is created and below code snippet is the value assigned to this variable and which is used within the execute SQl task. 创建一个新变量“ Newupquery ”,代码片段下方是分配给该变量的值,该值在execute SQl任务中使用。


DECLARE @UpdateRowCnt INT;
update countcheck
set [Base Unit of Measure] = 'PCS-1'
where [Base Unit of Measure] = 'PCS';
SELECT @UpdateRowCnt=@@ROWCOUNT;
Select @UpdateRowCnt

The above execute SQl task is executed and the result set is set to variable “ UpdateRowCount ”. 执行以上执行SQ1任务 ,并将结果集设置为变量“ UpdateRowCount ”。

The next step is another Execute SQL Task , which inserts the value of the variable UpdateRowCount to the log table in a stage server. 下一步是另一个Execute SQL Task ,它将变量UpdateRowCount的值插入到阶段服务器中的日志表中。 The value of variable UpdateRowCount was passed to insert statement using the parameter setting in Execute SQl Task. 使用Execute SQl Task中的参数设置将变量UpdateRowCount的值传递给insert语句

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

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