SQL Server stored procedure cursor usage, print output problem

Source: Internet
Author: User

...... N words are omitted here ...

DROP PROCEDURE Test_proc; CREATE PROCEDURE Test_proc as DECLARE @u_id INT;D eclare @u_name VARCHAR (255); DECLARE @age INT;--Declares the parameter in the cursor--select, must be the same as the variable name that the cursor takes out DECLARE mycursor cursor for SELECT u_id,u_name,age from U_us;--Open cursor O PEN MyCursor;--fetching data from a cursor, assigning to the 3 variables just defined fetch NEXT from mycursor into @u_id, @u_name, @age;--judging the state of the cursor--0 FETCH statement successful--1 fetch language A sentence fails or the row is not in the result set--2 fetched rows do not exist while (@ @fetch_status = 0) BEGIN
--print control output, be sure to turn to the same type print (' Number: ' +convert (varchar (one), @u_id) + ', name: ' [email protected]_name+ ', Age: ' + CONVERT (varchar (one), @age)); FETCH NEXT from MyCursor to @u_id, @u_name, @age; END; --Closing the cursor close mycursor; --Remove cursor deallocate mycursor;

...... N words are omitted here ...

--print control output, be sure to turn to the same type print (' Number: ' +convert (varchar (one), @u_id) + ',  name: ' [email protected]_name+ ',  Age: ' + CONVERT (varchar (one), @age));

  

SQL Server stored procedure cursor usage, print output problem

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.