日期:2014-05-18 浏览次数:21818 次
CREATE FUNCTION f_getobjectionveCodeByRESOURCEID (@RsourceID varchar(20),@index int) returns int as begin declare @objectiveCode int execute('select top '+@index+' '+@objectiveCode+'=objectiveCode from sco_e_objectives where ResourceID='+@RsourceID) return @objectiveCode end
ALTER FUNCTION f_getobjectionveCodeByRESOURCEID (@RsourceID varchar(20),@index int) returns int as begin declare @objectiveCode int, @SQL NVARCHAR(200) set @SQL='select top 1 @objectiveCode=objectiveCode from (select top '+@index+' objectiveCode from sco_e_objectives where ResourceID='+@RsourceID +')a'; EXEC SP_EXECUTESQL @SQL,N'@objectiveCode int', @objectiveCode OUT; return @objectiveCode end go
------解决方案--------------------
楼上,不是任何时候存储过程都能代替函数的,比方说这个返回值,我想用在select 后,即 select function_name(t.a) from Table t where ... [function_name为标量值函数名],这时存储过程就很无力了。对于这个错我也在找答案,忘哪位仁兄分享分享。。。