调用另一个用户定义函数中的SQL用户定义函数

时间:2021-12-16 20:23:57

I have the following UDF which i want to call another udf that split the result on return

我有下面的UDF,我想调用另一个UDF,它在返回时分割结果

-- =============================================
CREATE FUNCTION [dbo].[ufnGetValueForEmployeeTable]
(   
    @EeID       AS int,
    @ProvisionID    AS int,
    @optionName     AS varchar(4000)
)
RETURNS varchar(128)
AS
BEGIN
    SELECT 
    WHERE  
    RETURN **call here this function** GetOptionValueFromOtherOptions(@optionName ,  @value `this is the value from select` )

Is it possible ? if yes how?

是可能的吗?如果是如何?

2 个解决方案

#1


2  

I think you want something like:

我想你想要的是:

declare @retval varchar(128);

select . . .;

select @retval = GetOptionValueFromOtherOptions(@optionName ,  @value);

return @retval;

#2


0  

Try:

试一试:

RETURN (SELECT dbo.GetOptionValueFromOtherOptions(@optionName, @value));

However I suggest this with extreme caution: UDFs are bad enough on their own; nesting them will only compound the issue. Probably better to make the code that requires one function vs. the other to call them directly instead of using this nesting approach.

然而,我非常谨慎地建议:udf本身就足够糟糕了;嵌套它们只会使问题复杂化。也许更好的方法是编写需要一个函数与另一个函数直接调用它们的代码,而不是使用这种嵌套方法。

#1


2  

I think you want something like:

我想你想要的是:

declare @retval varchar(128);

select . . .;

select @retval = GetOptionValueFromOtherOptions(@optionName ,  @value);

return @retval;

#2


0  

Try:

试一试:

RETURN (SELECT dbo.GetOptionValueFromOtherOptions(@optionName, @value));

However I suggest this with extreme caution: UDFs are bad enough on their own; nesting them will only compound the issue. Probably better to make the code that requires one function vs. the other to call them directly instead of using this nesting approach.

然而,我非常谨慎地建议:udf本身就足够糟糕了;嵌套它们只会使问题复杂化。也许更好的方法是编写需要一个函数与另一个函数直接调用它们的代码,而不是使用这种嵌套方法。