在函数(SQL Server)中执动作态sql时堕落?
发布时间:2021-01-26 09:49:06 所属栏目:编程 来源:网络整理
导读:我建设一个函数来执动作态SQL并返回一个值.我获得“只有函数和一些扩展存储进程可以在函数内执行.”作为一个错误. 成果: Create Function fn_GetPrePopValue(@paramterValue nvarchar(100))returns int asbegindeclare @value nvarchar(500);Set @SQLString
我建设一个函数来执动作态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 执行: Select dbo.fn_GetPrePopValue('10002618') from Questions Where QuestionID=114 和: Select fn_GetPrePopValue('10002618') from Questions Where QuestionID=114 成果是正确挪用照旧函数不正确? 办理要领您不能行使函数中的动态SQL,也不能挪用存储进程. Create proc GetPrePopValue(@paramterValue nvarchar(100)) as begin declare @value nvarchar(500),@SQLString nvarchar(4000) Set @SQLString = 'Select @value = Grant_Nr From Grant_Master where grant_id = @paramterValue' exec sp_executesql @SQLString,N'@paramterValue nvarchar(100)',@paramterValue,@value = @value output return @value end (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |