DEV Community

baris
baris

Posted on

Answer: SQL Call Stored Procedure for each Row without using a cursor

DECLARE @SQL varchar(max)=''

-- MyTable has fields fld1 & fld2

Select @SQL = @SQL + 'exec myproc ' + convert(varchar(10),fld1) + ',' 
                   + convert(varchar(10),fld2) + ';'
From MyTable

EXEC (@SQL)

Ok, so I would never put such code into production, but it does satisfy your requirements.

</p>





Short but not the best way to do it.

Top comments (0)