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
 Cursor to call a stored procedure?

Author  Topic 

alanw64
Starting Member

4 Posts

Posted - 2009-11-17 : 17:44:42
Ok, I'm not quite sure how to do this, but while I'm still searching for answers, I thought I'd send my question out to the SQL Team universe to see what comes back.

I have a stored procedure that works right now; it accepts a year parameter, like this:

sp_process_year 2009

After it finishes, then I have to change the year and run it again. I have to run it for years 2010 - 2003.

Can anyone offer any suggestions about modifying the stored procedure to run recursively, passing in the years 2010, then 2009, then 2008, etc. down to 2003 and then stop?

Thank you very much for any help or suggestions!

Alan

Fall down seven, stand up eight.
~Japanese Proverb

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-11-17 : 17:54:13
You could use a WHILE loop, but that seems excessive for just 7 calls. Can't you just loop from within your application?

Or better yet modify the stored procedure to accept a begin year and end year parameters and return one result set with all of the data and then your application can split it up by year.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

alanw64
Starting Member

4 Posts

Posted - 2009-11-17 : 18:22:48
Hi Tara,

I won't be calling the proc from an application -- just running it "manually", but you've given me some good ideas. Thank you!

Fall down seven, stand up eight.
~Japanese Proverb
Go to Top of Page
   

- Advertisement -