I want to loop through a bunch of different functions and execute them inside a stored procedure. For example, if I have the function names:
- Function1
- Function2
- Function3
And I want to call each using the variable name, @fn
, how do I do that? I already know how to store the functions inside @fn
and loop using a cursor, but do not know how to execute it. The following is what I've tried:
declare @fn nvarchar(30) = 'Function1',
@sql varchar(500);
set @sql = N'select * from dbo.' + @fn + '(101)';
exec @sql;
I've also tried exec sp_executesql @sql;
Thanks!