我知道这已被要求死亡,我知道为什么SQL Server不允许你这样做.
但除了使用扩展存储过程之外,还有其他解决方法吗?
请不要告诉我将我的功能转换为程序...
所以我真正要问的是:有没有办法从函数中运行存储过程?
编辑:
有点证明:有一种解决方法,但它是如此错误,我不会这样做.我要将其更改为存储过程并在其他地方执行.
sql sql-server stored-procedures sql-server-2005 user-defined-functions
我创建一个函数来执行动态SQL并返回一个值.我得到"只有函数和一些扩展存储过程可以在函数内执行." 作为一个错误.
功能:
Create Function fn_GetPrePopValue(@paramterValue nvarchar(100))
returns int as
begin
declare @value nvarchar(500);
Set @SQLString = 'Select Grant_Nr From Grant_Master where grant_id=' + @paramterValue
exec sp_executesql
@query = @SQLString,
@value = @value output
return @value
end
Run Code Online (Sandbox Code Playgroud)
执行:
Select dbo.fn_GetPrePopValue('10002618') from Questions Where QuestionID=114
Run Code Online (Sandbox Code Playgroud)
和:
Select fn_GetPrePopValue('10002618') from Questions Where QuestionID=114
Run Code Online (Sandbox Code Playgroud)
功能是正确调用还是函数不正确?