2016-07-29 39 views
0
UPDATE b 
SET b.update_flag=0 
from table1 a 
inner join table2 b on a.user_code=b.user_code 
where a.pin_number IS NULL 

UPDATE a 
SET a.pin_number = Adinfo.dbo.udf_ad_Encrypt(b.pin_number) 
from table1 a 
inner join table2 b on a.user_code=b.user_code 
where a.pin_number IS NULL 

有人可以帮助我,我怎么能写在SQL Server中输出条款2更新语句输出条款

+2

你是什么意思,“输出条款”?你的意思是这是一个存储过程? –

+0

我应该使用output关键字并从第二个更新语句中获取值,并将这些值插入第一个更新语句中。它可以通过使用输出子句来完成。 – Durga

+1

更新没有“输出”,除了它们影响的行数外,也许。 –

回答

-1

我看到的问题是什么:I should use output keyword and get the values from the second update statement and get those values inserted in first update statement. It can be done by using output clause. – Durga

你只需要改变你的更新陈述'的地方。
首先,您在表“b”中更新pin_number,然后在表“a”中将所有update_flag设置为“1”。

然后你根本不需要输出。只有一个限制:你必须把它包装在事务中。

BEGIN TRANSACTION 

UPDATE a 
SET a.pin_number = Adinfo.dbo.udf_ad_Encrypt(b.pin_number) 
from table1 a 
inner join table2 b on a.user_code=b.user_code 
where a.pin_number IS NULL 

UPDATE b 
SET b.update_flag=0 
from table1 a 
inner join table2 b on a.user_code=b.user_code 
where a.pin_number IS NULL 

COMMIT TRANSACTION 
+0

是的。我使用这种方法。但我想用output子句来获取它。 – Durga

+0

我建议更简单的方法。你没有告诉你为什么要使用'OUTPUT'。我假设你知道如何找到关于如何使用它的文档。 –