Click here to Skip to main content
15,912,507 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!

i want to call a procedure recursively in mssql as below given format:

start loop
exec procedure (loop value);
end loop

thanks in advance.
Posted
Comments
thatraja 5-May-14 4:01am    
What's the purpose?

sample SQL
SQL
DECLARE @I INT

SET @I = 1

WHILE @I <= 10
BEGIN
    exec yourStoredProcedureName
    SET @I = @I + 1
END
 
Share this answer
 
declare @i int=0

while(@i<12)
begin
select 1
set @i=@i+1
end

there is mistake in declaring @i variable
 
Share this answer
 
v3
Comments
saifullahiit 5-May-14 4:13am    
i apply your query like
declare @i=85 int

while(@i<348)
begin
exec procedurexyz @i
set @i=@i+1
end

and i receive the following error.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '='.
Msg 137, Level 15, State 2, Line 3
Must declare the scalar variable "@i".
Msg 137, Level 15, State 2, Line 5
Must declare the scalar variable "@i".
Msg 137, Level 15, State 2, Line 6
Must declare the scalar variable "@i".
Darshan.Pa 5-May-14 4:19am    
check updated sollution
You have to use "LOCAL" CURSOR for that:
Cursor
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900