如何在单个事务中运行多个查询 [英] How to run multiple query in a single transaction

查看:65
本文介绍了如何在单个事务中运行多个查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我有以下查询,我希望在一次交易中运行3次。

请告诉我怎么做

  update  transaction_details  set  transaction_details.status = 3 
来自 transaction_details,commodity_codes
其中 transaction_details.status = 2
transaction_details.item_code = commodity_codes.ahara_commodity_code
bill_no = < span class =code-string>' + _with1 [BillNo] +'
transaction_details.trans_date = ' + _with1 [Date] +'

解决方案

 开始  tran  t1 
您的查询 1
您的查询 2
您的查询 3

IF @@ ERROR <> 0 BEGIN
PRINT ' 发生意外错误!'
ROLLBACK TRAN
RETURN 1
END
else
BEGIN
commit tran t1


Hi all

I have this below query and i want to run this 3 times under a single transaction.
Please tell me how to do this

update transaction_details set transaction_details.status=3 
from transaction_details, commodity_codes  
where transaction_details.status=2 
  and transaction_details.item_code=commodity_codes.ahara_commodity_code 
  and bill_no='" + _with1["BillNo"] + "' 
  and transaction_details.trans_date ='" + _with1["Date"] + "'

解决方案

Begin tran t1
your query 1
your query 2
your query 3

 IF (@@ERROR <> 0) BEGIN
        PRINT 'Unexpected error occurred!'
        ROLLBACK TRAN
        RETURN 1
    END
else
BEGIN
commit tran t1
end


这篇关于如何在单个事务中运行多个查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆