Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a stored procedure multiple times

I have a stored procedure which i execute like this:

exec sp_storedProc '123','ME', '333',NULL

I have 400 different values I need to specify. How do I execute my stored procedure with different values at once?

like image 806
PriceCheaperton Avatar asked Jul 16 '14 13:07

PriceCheaperton


1 Answers

You may try to do it using CURSORS

DECLARE @param INT

DECLARE curs CURSOR LOCAL FAST_FORWARD FOR
    SELECT parameter FROM table_name WHERE ...

OPEN curs

FETCH NEXT FROM curs INTO @param

WHILE @@FETCH_STATUS = 0 BEGIN
    EXEC sp_storeProc  @param
    FETCH NEXT FROM curs INTO @param
END

CLOSE curs
DEALLOCATE curs
like image 183
Rahul Tripathi Avatar answered Sep 28 '22 06:09

Rahul Tripathi