TSQL Sending Multiple rows to a stored procedure

vsslasd 556 Reputation points
2022-04-28T20:46:26.937+00:00

I need to send multiple rows to a stored procedure that is written to receive one record at a time. I can use a cursor, but would prefer to see if there are other options.

Are there other options to send multiple rows to a stored procedure for execution, or is cursor the only way ?

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,555 questions
0 comments No comments
{count} votes

Accepted answer
  1. Naomi 7,361 Reputation points
    2022-04-28T20:52:10.037+00:00

    If the stored procedure can be re-written, it may better be written to accept table-valued parameter instead of one row at a time. If the stored procedure must remain as it is now, then there is not many other choices besides a cursor (or some other loop processing) or there is probably also a possibility to make a dynamic script invoking this procedure for several rows of data and then execute generated script using sp_executeSQL procedure.


1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 101.4K Reputation points MVP
    2022-04-28T21:39:28.49+00:00

    I have an article on my web site entitled How to Share Data Between Stored Procedures that disusses options in this space.

    1 person found this answer helpful.