SQL Server stored Procedure cursor instance

Source: Internet
Author: User

ifExistsSelect* fromsysobjectswhereid = object_id (N'Dbo.test_cursor') and type ='P') Drop PROCEDURE dbo.test_cursorgoset ansi_nulls ongoset quoted_identifier ongocreate PROCEDURE test_ Cursorasdeclare @acctNbr varchar ( -);D eclare @acctName nvarchar ( -);D eclare mycursor Cursor forSelect Acctnbr,acctname fromBase. _member Order by Idopen Mycursorfetch next from MyCursor into @acctNbr, @acctName while(@ @fetch_status =0) BEGIN begin Select @acctNbr= Convert (varchar ( -), @acctNbr) Select @acctName= Convert (nvarchar ( -), @acctName) print N'Membership card number:'[Email protected] + N'-----Member Name:'+@acctName end Fetch NEXT from MyCursor to @acctNbr, @acctName endclose mycursordeallocate MYCU Rsor--execute Test_cursor

SQL Server stored Procedure cursor instance

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.