SQL stored procedures, using transactions (Try Catch), cursors

Source: Internet
Author: User

CREATEProc[Dbo].[Sys_rebate_equity]AsDeclare@fMemberIDvarchar50)--User IDDeclare@RebateDecimal18,2)--Total number of sharesBEGINBeginTryBeginTransaction--Start a transactionDECLARE Cursor1CURSORFor--Defining Cursors Cursor1Select Fmemberid,SUM (fnumber)As‘Fnumber‘From bp_equitywhere Fnumber>0Groupby Fmemberid--Objects that use cursorsOpen Cursor1--Open cursorFetchNextFrom Cursor1Into@fMemberID,@Rebate--Move the cursor down by 1 rows to get the data into the previously defined variable @fmemberid, @RebateWhile@ @FETCH_STATUS=0--Determine if the data was successfully obtainedBeginSelect1--To handle accordinglyFetchNextFrom Cursor1Into@id--Move the cursor down by 1 rowsEndClose Cursor1--Close CursorsDeallocate Cursor1--To delete a cursor referenceSelect888commit transaction --< Span style= "color: #008080;" > COMMIT transaction end Try begin< Span style= "color: #000000;" > Catch if @ @trancount > 0 rollback transaction -- ROLLBACK TRANSACTION 8888 end Catch end           

SQL stored procedures, using transactions (Try Catch), cursors

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.