Use of SQL Server cursors

Source: Internet
Author: User

DECLARE @temp_temp uniqueidentifier--temporary variable    declare AAA cursor for select Id from A-------------------open A cursor The aaa--first queries the recirculation to prevent multiple cursors when @ @FETCH_STATUS =-1 cannot enter the next cursor loop FETCH next from the AAA into @temp_ The temp-------------------loops through the data while @ @FETCH_STATUS =0beginprint @temp_tempfetch next from AAA into @temp_ Tempend-----------------------------------close a cursor close    AAA    -----------------------------------Delete a cursor    DEALLOCATE AAA

  

Nesting of cursors

DECLARE @temp_temp uniqueidentifier--temporary variable    declare AAA cursor for select Id from A-------------------open A cursor The aaa--first queries the recirculation to prevent multiple cursors when @ @FETCH_STATUS =-1 cannot enter the next cursor loop FETCH next from the AAA into @temp_ Temp-------------------loop Fetch data while @ @FETCH_STATUS =0beginprint @temp_temp--=========================== cursor Nesting DECLARE BBB cursor FOR select Id from B-------------------Open the cursor opening bbb--first to query the recirculation, to prevent multiple cursors @ @FETCH_STATUS =-1 cannot enter the next cursor loop in the case of FETCH Next from the BBB into @temp_temp-------------------loop to fetch the data while @ @FETCH_STATUS =0beginprint @temp_tempfetch next from the BBB into @temp_tempend-----------------------------------Close cursors close    bbb    -----------------------------------Delete Cursors    deallocate bbb--=========================== cursor nesting fetch NEXT from AAA to @temp_ Tempend-----------------------------------close a cursor close    AAA    -----------------------------------Delete a cursor    DEALLOCATE AAA

  

Use of SQL Server 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.