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
 General SQL Server Forums
 New to SQL Server Programming
 Stored Recursive Procedure

Author  Topic 

Beginner
Starting Member

1 Post

Posted - 2007-03-11 : 19:25:03
Hi,
I would like some help on a stored recursive procedure I have been working on for my assigment. I had the solution from my course master some time back, but accidentally deleted the file before finishing the course, and would like the solution to that problem.
The questions are as follows:
1) Create a recursive stored procedure that counts from 1 to 10
2) Create a recursive stored procedure that counts from 10 to 1

I believe there's more than one approach in solving these procedures, and any feeback is welcome.

cheers

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-12 : 02:10:58
I am giving you proc for printing 1 to 10. You can write other one yourself.

-- Recursive proc for printing 1 to 10
create proc rec_one_to_ten
(
@a int = 1
)
as
begin
if @a > 10
return
else
begin
print @a
set @a = @a + 1
exec rec_one_to_ten @a
end
end


To execute this procedure:

exec rec_one_to_ten


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -