存储过程计数(*)

时间:2013-05-14 14:53:57

标签: sql-server stored-procedures

我有这个存储过程:

CREATE PROCEDURE [dbo].[getCorrespondingRespcode]
@rc char(3)
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @webRcCount int

    SELECT webRc, COUNT(*) as webRcCount  
    FROM payterm.response_codes_mapping  
    WHERE rc = @rc GROUP BY webRc
END

如何使用@webRcCount的值设置webRcCount?我需要做if @webRcCount = 1 print'ok'

2 个答案:

答案 0 :(得分:2)

SELECT @webRcCount = COUNT(*) 
FROM payterm.response_codes_mapping 
WHERE rc = @rc

SELECT @webRcCount AS [WebRCCount]

应该这样做......

答案 1 :(得分:0)

您是否要在表格中计算不同的 webRc值?如果是这样,请改用:

SELECT @webRcCount = COUNT(DISTINCT webRC) 
FROM payterm.response_codes_mapping 
WHERE rc = @rc;