在select中包含存储过程的输出

时间:2013-06-20 18:01:44

标签: sql-server

我有一个这样的存储过程:

create proc calcaulateavaerage
@studentid int
as
begin

-- some complicated business and query

return @result  -- single decimal value 
end

然后我想

创建proc整个结果

select * , ................................ from X where X.value >  (calculateaverage X.Id)

它总是给出一个错误,读起来像“多部分标识符calculateaverage无法绑定”。知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:4)

您不需要存储过程。你想要一个功能。

答案 1 :(得分:2)

使用输出变量从存储过程中输出数据:

create proc calcaulateavaerage
@studentid int, @result int
as
begin

-- some complecated business and query

select @result = id from sometable;
end

-- Declaring output variable named result;
declare @result int;
-- Passing output variable to stored procedure.
exec calculateaverage 1, @result;

-- Now you can display the result or do whatever you like.
print @result