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

Source: Internet
Author: User
Tags try catch

CREATE proc [dbo].[sys_rebate_equity]        asDeclare @fMemberID varchar( -)--User IDDeclare @Rebate decimal( -,2)--total number of shares   BEGIN    beginTryBegin Transaction    --Start a transaction        DECLARECursor1CURSOR  for        --Defining Cursors Cursor1        SelectFmemberid,sum(Fnumber) as 'Fnumber'  fromBp_equitywhereFnumber>0 Group  byFmemberid--objects that use cursors         OpenCursor1--Open Cursor         Fetch Next  fromCursor1 into @fMemberID,@Rebate    --move the cursor down by 1 rows to get the data into the previously defined variable @fmemberid, @Rebate          while @ @FETCH_STATUS=0    --determine if the data was successfully obtained             begin                Select 1    --to handle accordingly                Fetch Next  fromCursor1 into @id    --move the cursor down by 1 rows            End        CloseCursor1--Close Cursors        deallocateCursor1--To delete a cursor reference        Select 888     Commit Transaction    --Commit a transaction    EndTryBeginCatchif @ @trancount > 0 ROLLBACK TRANSACTION --rolling back a transaction        Select 8888            EndCatchEND

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.