存储过程执行输出错误

时间:2014-04-11 18:29:09

标签: sql sql-server sql-server-2008 stored-procedures

这是我的存储过程代码:

CREATE PROCEDURE dbo.EnrollStudent ( @CourseID  AS INTEGER,
                                     @StudentID AS VARCHAR(20), 
                                     @Status AS VARCHAR(50) OUTPUT ) AS
BEGIN
   DECLARE @StutusID INTEGER

   IF @StutusID = 1
   BEGIN  
       SET @Status = 'The Student is already Enrolled'
   END;

   ELSE IF @StutusID = 2
   BEGIN 
       SET @Status = 'Cannot enroll until faculty is selected' 
   END

   ELSE IF @StutusID = 3
   BEGIN 
       SET @Status = 'Student Enrolled' 
   END

   IF EXISTS (SELECT 1 
                FROM dbo.CourseEnrollment 
                WHERE dbo.CourseEnrollment.CourseId=@CourseID AND dbo.CourseEnrollment.StudentId=@StudentID )
   BEGIN
      SET @StutusID = 1
   END


END;

这就是我试图执行它的方式......

DECLARE @Status1 VARCHAR(50)
EXEC dbo.EnrollStudent @CourseID=1, @StudentID='01-HJPotter', @Status= @Status1 OUT;

这就是我得到的错误

  

Msg 8144,Level 16,State 2,Procedure EnrollStudent,Line 0
  过程或函数EnrollStudent指定了太多参数。

有人能告诉我哪里出错了吗?

由于

1 个答案:

答案 0 :(得分:0)

你为什么要申报?试试这个。

CREATE PROCEDURE dbo.EnrollStudent ( @CourseID  AS INTEGER,
                                 @StudentID AS VARCHAR(20), 
                                 @Status AS VARCHAR(50) OUTPUT ) AS
BEGIN

IF @StutusID = 1
BEGIN  
    SET @Status = 'The Student is already Enrolled'
END;

ELSE IF @StutusID = 2
BEGIN 
   SET @Status = 'Cannot enroll until faculty is selected' 
END

ELSE IF @StutusID = 3
BEGIN 
   SET @Status = 'Student Enrolled' 
END

IF EXISTS (SELECT 1 
            FROM dbo.CourseEnrollment 
            WHERE dbo.CourseEnrollment.CourseId=@CourseID AND       dbo.CourseEnrollment.StudentId=@StudentID )
BEGIN
  SET @StutusID = 1
END


END;