如何使存储过程检查它的输入参数并在超出限制时返回?

时间:2014-07-25 13:42:06

标签: sql-server

我开始编写存储过程:

CREATE PROCEDURE [dbo].[sp_prepare_data]
    @SubjectId      INT
AS
BEGIN

END

如果传递给存储过程的SubjectId 100,200或300,我怎样才能使存储过程返回RC为99?

1 个答案:

答案 0 :(得分:1)

CREATE PROCEDURE [dbo].[usp_prepare_data]  --<-- Use usp_ instead of sp_
     @SubjectId      INT
AS
BEGIN
   IF(@SubjectId = 100 OR @SubjectId = 200 OR @SubjectId = 300)
      BEGIN
        -- Your code goes here
      END 
   ELSE 
    BEGIN
        RETURN 99;
    END
END