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
 How to make a recursion in a store procedure?

Author  Topic 

roykauf
Starting Member

36 Posts

Posted - 2008-07-30 : 08:37:06
Hello,

Can someone please tell me how to write a recursion in a store procedure and how can I add a suitable stopping condition ?

Please send me a short feedback!

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-30 : 08:38:38
quote:
Originally posted by roykauf

Hello,

Can someone please tell me how to write a recursion in a store procedure and how can I add a suitable stopping condition ?

Please send me a short feedback!


What do you want to do with recursion?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

roykauf
Starting Member

36 Posts

Posted - 2008-07-30 : 09:19:10
I want to send alerts by mail. every alert from the alerts table
is marked with a flag (sent or not). I want to send each alert from the query , and i thought to do it with recursion till there are no alerts left with a flag of 'not sent'
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-07-30 : 09:37:15
That's not recursion. That is simple looping. Use a Cursor to do this.

e4 d5 xd5 Nf6
Go to Top of Page

roykauf
Starting Member

36 Posts

Posted - 2008-07-30 : 09:38:31
can you give me an exmaple please?
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-07-30 : 09:50:57
Just look up Declare Cursor in Books Online and it will show you examples of how to declare a cursor, open it, fetch consecutive records, close it, and deallocate it.

e4 d5 xd5 Nf6
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-30 : 09:54:53
I think it can be done with help of while loop as well.
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-07-30 : 11:21:59
A cursor would be faster.

e4 d5 xd5 Nf6
Go to Top of Page
   

- Advertisement -