Matrix001
Matrix001

Reputation: 1272

Problem with a stored procedure

ALTER PROCEDURE dbo.ModeratorSpamDeleteComment


  DECLARE @CommentID int;



AS
  BEGIN
    DELETE Comments
    WHERE CommentsID=@CommentID
  END

It says i have an incorrect syntax near "AS" and "Declare"..

I want to deliver the store procedure the CommentID parameter and execute the delete statement..

Upvotes: 1

Views: 68

Answers (4)

MartinHN
MartinHN

Reputation: 19772

Just get rid of DECLARE:

ALTER PROCEDURE dbo.ModeratorSpamDeleteComment
@CommentID int
AS


  BEGIN
    DELETE Comments
    WHERE CommentsID=@CommentID
  END

Upvotes: 2

Jonathan Wood
Jonathan Wood

Reputation: 67175

Move the DECLARE into your procedure body (between BEGIN and END). The area it's in now is for procedure parameters.

Upvotes: 1

Alex K.
Alex K.

Reputation: 175748

Don't DECLARE the arguments;

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

Upvotes: 2

Quassnoi
Quassnoi

Reputation: 425251

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

Upvotes: 3

Related Questions