Sql 用于返回输出参数的语法

Sql 用于返回输出参数的语法,sql,sql-server,tsql,stored-procedures,Sql,Sql Server,Tsql,Stored Procedures,我有一个存储过程,其中有一个输出参数。当我在SQLServerManagementStudio中运行查询时,我得到了正确的答案。我的问题是为输出参数指定答案。以下是存储过程: ALTER PROCEDURE [dbo].[RDusp_Report_Impact] -- Add the parameters for the stored procedure here @SiteID int, @RiskCount int output AS BEGIN SET NOCOUNT ON;

我有一个存储过程,其中有一个输出参数。当我在SQLServerManagementStudio中运行查询时,我得到了正确的答案。我的问题是为输出参数指定答案。以下是存储过程:

ALTER PROCEDURE [dbo].[RDusp_Report_Impact] 
 -- Add the parameters for the stored procedure here
 @SiteID int,
 @RiskCount int output 
AS
BEGIN
 SET NOCOUNT ON;



select sum(cnt) as mytotal from
(
select count(Impact.Rating) as cnt from Impact, Likelihood, Exposure where
 Impact.SiteID=2
and Exposure.SiteID = 2 and Impact.Rating > 3 and Likelihood.Rating > 3
and Exposure.ImpactID = Impact.ImpactID and exposure.LikelihoodID = Likelihood.LikelihoodID
) as c


END

我试图将@RiskCount指定为mytotal中的值,但它表示该列不存在。我只想把那个结果拿回来。应该不会太难,只是语法上的问题我不懂。谢谢。

这样修改您的查询(关键部分是SELECT语句的第一行-
SELECT@RiskCount=sum(cnt)

这样执行:

DECLARE @rc int
EXEC [dbo].[RDusp_Report_Impact] 123, @rc output  -- 123 is an example @SiteID value
SELECT @rc

EXEC需要添加@SiteIDvalue@Marek如果我的select语句包含多个列,即select RiskCount=sum(cnt),EXPORATION.SiteID,那么语法应该是什么?如果我的问题不太清楚,请查看一下,我正在等待答复
DECLARE @rc int
EXEC [dbo].[RDusp_Report_Impact] 123, @rc output  -- 123 is an example @SiteID value
SELECT @rc