Update the inserted SQL transaction statement using the cursor Loop
Source: Internet
Author: User
-- Start transaction
Begin tran
-- Do Not Display count Information
Set nocount on
Declare @ userid varchar (512)
Declare @ A int
Set @ A = 10000
-- Declare a cursor
Declare crmpscontact_cursor cursor
Select [userid] from [gmcc]. [DBO]. [cvv_users]
-- Open the cursor
Open crmpscontact_cursor
-- Return the value of the first row to the variable.
Fetch next from crmpscontact_cursor
Into @ userid
-- Execute the statement
Update [gmcc]. [DBO]. [cvv_users]
Set [workid] = @
Where [userid] = @ userid
Set @ A = @ A + 1
-- Execution error rollback
If @ error! = 0
Begin
Rollback tran
Return
End
-- Move the cursor and update all other rows (exit when the cursor ends)
While @ fetch_status = 0
Begin
-- Move the cursor to the next row
Fetch next from crmpscontact_cursor
Into @ userid
-- Execute the statement, starting from the second line
Update [gmcc]. [DBO]. [cvv_users]
Set [workid] = @
Where [userid] = @ userid
Set @ A = @ A + 1
-- Execution error rollback
If @ error! = 0
Begin
Rollback tran
Return
End
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.