How to use circular statements in SQL SERVER 2005 stored procedures _mssql2005

Source: Internet
Author: User

Copy Code code as follows:

creat PROCEDURE Tester
As
BEGIN
SET NOCOUNT on;
DECLARE @userId varchar (50)
DECLARE @count int
SET @count = 0
SELECT @count = count (*) from Userservice_user WHERE account like '%111% '
While @count > 0
BEGIN
SELECT @userId = Id from Userservice_user WHERE account like '%111% '
EXEC Userservice_removeuserbyuserid @userId
SET @count = @count-1
End
End

Description:
1. This stored procedure is tested on SQL SERVER 2005, and it is noteworthy that in the loop body, the statement is using the BEGIN ... End is included, not what is often said on the network ... End while structure, other loop statements, such as loop ... UNTIL ... The end loop is also not compiled, perhaps a version of the problem, but in SQL SERVER2005, the loop body uses the BEGIN ... End is OK, and you can't use a while that is often said on the network ... End-while structure.

2, the loop body userservice_removeuserbyuserid is a stored procedure name, @userId for the stored procedure parameters, if there are more than one parameter, use "," separate it, which is also a stored procedure to invoke another stored procedure method.

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.