存储过程出现问题

时间:2011-07-15 12:05:08

标签: asp.net sql stored-procedures

ALTER PROCEDURE dbo.ModeratorSpamDeleteComment


  DECLARE @CommentID int;



AS
  BEGIN
    DELETE Comments
    WHERE CommentsID=@CommentID
  END

它说我在“AS”和“声明”附近的语法不正确..

我想将存储过程传递给CommentID参数并执行delete语句..

4 个答案:

答案 0 :(得分:3)

ALTER PROCEDURE
        dbo.ModeratorSpamDeleteComment
                @CommentID INT
AS
        DELETE
        FROM    Comments
        WHERE   CommentsID = @CommentID

答案 1 :(得分:2)

摆脱DECLARE:

ALTER PROCEDURE dbo.ModeratorSpamDeleteComment
@CommentID int
AS


  BEGIN
    DELETE Comments
    WHERE CommentsID=@CommentID
  END

答案 2 :(得分:2)

不要DECLARE参数;

ALTER PROCEDURE dbo.ModeratorSpamDeleteComment
( --parens are optional but clearer imo
   @CommentID int
)
AS --don't need BEGIN/END in this case

DELETE FROM Comments
   WHERE CommentsID=@CommentID

答案 3 :(得分:1)

DECLARE移到您的程序正文中(BEGINEND之间)。它现在的区域是程序参数。