SQL Server Stored Procedures and cursors

Source: Internet
Author: User

 

If exists (

Select *

From DBO. sysobjects

Where id = object_id (n' [DBO]. [sp_check_qq] ')

And objectproperty (ID, n' isprocedure ') = 1

)

Drop procedure [DBO]. [sp_check_qq]

Go

 

Create procedure DBO. sp_check_qq

-- Used to check whether all QQ numbers are numbers without Variables

As

-- Mainly refers to exercise cursor

-- Declare the cursor

Declare @ Q varchar (10)

Declare @ ID integer

Declare @ s varchar (8000)

/*

* Define a cursor

*/

Declare cur_ii cursor

Select ii_id, QQ from II

/*

* Open a cursor

*/

 

Open cur_ii

/*

* Extract records

*/

 

Fetch next from cur_ii into @ ID, @ Q

Set @ s =''

/*

* Loop and extract records

*/

While (@ fetch_status = 0)

Begin

If DBO. is_all_number (@ q) = 0

Set @ s = @ s + ',' + Cast (@ ID as varchar (10 ))

Fetch next from cur_ii

Into @ ID, @ Q

End

/*

* Close the cursor

*/

Close cur_ii

/*

* Delete A cursor reference

*/

Deallocate cur_ii

Set @ s = right (@ s, Len (@ s)-1)

Select @ s

/*

Exec sp_check_qq

*/

Go

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.