SQL Add transaction Processing

Source: Internet
Author: User
Tags getdate

Tag: date () Exist Port OCA tab request Item Transaction Sele

--modi by LMT
Declare
@errorSum INT--record number of errors
Begin
Create table #CheckreqAccState (checkreqid varchar, advid varchar), docadvstatus int, accstate varchar (20))
Set @SqlTxt = ' INSERT into #CheckreqAccState (checkreqid, Advid, Docadvstatus, accstate)
Select A.checkreqid, A.advid, B.docadvstatus, accstate from Ghmtdb. Tcheckreq_main (NOLOCK) A left join GHMTDB.dbo.tRecipe_Detail (NOLOCK) B on a.advid = B.advid
where a.checkreqid in (' + @CheckReqID + ') '
EXEC (@SqlTxt)
if exists (SELECT * from #CheckreqAccState where Docadvstatus < 3)
Begin
Set @ReqInfor = ' true fee failure: ' ' + @CheckReqID + ' in the application number, please verify that there are no charges recorded.
drop table #CheckreqAccState
Goto ERR
End
Else
BEGIN TRANSACTION
Update Ghmtdb. Tcheckreq_main
Set state = 3, Reportuser = @OperUserID, reportdate = GetDate ()
Where checkreqid in (select Checkreqid from #CheckreqAccState)
Set @[email protected] + @ @error
Update Trecipe_detail
Set Performuserid = @OperUserID, Docadvstatus = 5,
Performdate = GETDATE ()
where Advid in (select Advid from #CheckreqAccState)
Set @[email Protected][email protected] @error
Update Trecipe_detail_feeitem
Set Performuserid = @OperUserID, Docadvstatus = 5,
Performdate = GETDATE ()
where Advid in (select Advid from #CheckreqAccState)
Set @[email Protected][email protected] @error
Update Tchargedetail
Set Performuserid = @OperUserID, Docadvstatus = 5,
Performdate = GETDATE ()
where Advid in (select Advid from #CheckreqAccState)
Set @[email Protected][email protected] @error
drop table #CheckreqAccState
If @errorSum > 0
Begin
Set @ReqInfor = ' execution failed '
Select @ReqInfor ' reqinfor ', @ChargeSN ' CHARGESN '
ROLLBACK TRANSACTION
End
Else
Begin
Set @ReqInfor = ' Execute complete '
Select @ReqInfor ' reqinfor ', @ChargeSN ' CHARGESN '
Commit TRANSACTION
End
End
End--end Else if @DataSource = ' outpatient '
End--modi End

SQL Add transaction Processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.