DEV Community

loading...

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

boyukbas profile image baris ・1 min read
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.

Discussion (0)

pic
Editor guide