Re: Function to call function by name given as parameter > Had you been in a stored procedure, you could have used dynamic SQL. Now
> you are in a function, and the only way to do this is:
>
> IF @f = 'that_func'
> RETURN (dbo.that_func(@f))
> ELSE @f = 'this_func'
> RETURN (dbo.that_func(@f))
> etc
But I want to call this_func or that_func, or maybe a few other
functions without a need to modify wrapper function. Somehow I managed
to write stored procedure which does what I want:
CREATE PROCEDURE [dbo].[f] @funkcja varchar(50), @arg1 varchar(50),
@koszt money OUTPUT
AS
BEGIN
declare @cmd nvarchar(50)
declare @par nvarchar(50)
set @cmd=N'set @koszt='+@funkcja+'(@arg)'
set @par=N'@koszt money output, @arg varchar(50)'
execute sp_executesql @cmd, @par, @koszt output, @arg=@arg1
END
Now I have onother problem: SPs cannot be used inside functions.
Only functions and extended SPs. Can I write extended SP to execute
SPs from functions?
Mariusz |