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.