Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Recursive Stored Procedure

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-09-22 : 07:32:37
Venedict writes "Dear Sir/Madam,

Is it possible to write a recursive loops within the Stored Procedure?

If so, how should i write the Store Procedure?

Thanks.

Regards,
Venedict"

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-09-22 : 07:57:44
Yes, you can easily use WHILE (condition) BEGIN ... END to loop within a stored procedure.

FYI --

"recursive" = a stored procedure calling itself, no loops involved.

"iterative" = loops within a stored procedure that does NOT call itself.


- Jeff
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-09-22 : 08:08:21
create procedure spLoop @i int
as
if @i<32
begin
print 'This is step #' + cast(@i as varchar(8))
set @i=@i+1
exec spLoop @i
end
return
GO

exec spLoop @i=7
Go to Top of Page
   

- Advertisement -