SQL Server access Procedure-cursors

Source: Internet
Author: User

ALTER proc [dbo]. [COMMON_PROC_TEMP2]

As begin

declare @id varchar ()
declare @cbcontractid varchar;
DECLARE @ XH int;
Declare owner_03_cursor cursor scroll
for select ID from cb_contract where canton_id like ' 20% '
--2. Open Cursor
Open Owner_03_cursor
Fetch next from owner_03_cursor into @cbcontractid the number of variables in the--into must be the same as the number of columns in the cursor query result set
while @ @fetch _status=0--extraction succeeds, extract operation for next data
Begin
Set @xh =1
Declare owner_04_cursor cursor scroll
for select ID from CB _contract_change where [email protected] ORDER by BGRQ ASC
Open Owner_04_cursor
Fetch NEXT from owner_04_curs or into @id
while @ @fetch_status =0
Begin
Update cb_contract_change set [email protected] where [email&nb Sp;protected]
Set @[email protected]+1;
fetch NEXT from owner_04_cursor to @id
End
Close owner_04_ Cursor
deallocate owner_04_cursor;

FETCH NEXT from Owner_03_cursor to @cbcontractid--move cursor
End
Close owner_03_cursor;
Deallocate owner_03_cursor;
End

SQL Server access Procedure-cursors

Related Article

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.