简体   繁体   English

2对输出子句的更新语句

[英]2 update statements to output clause

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 

Can someone help me how can I write this with output clause in sql server 有人可以帮我如何在SQL Server中使用output子句编写此代码

I see what the problem is: 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 我明白了问题所在: 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 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

You just have to change your update statements' places. 您只需要更改更新语句的位置即可。
At first you update pin_number in table "b" and then set to "1" all update_flag in table "a". 首先,您更新表“ b”中的pin_number ,然后将表“ a”中的所有update_flag设置为“ 1”。

Then you wouldn't need output at all. 然后,您根本不需要输出。 Only one restriction: you have to wrap it inside of transaction. 仅有一个限制:您必须将其包装在事务中。

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

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

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