user311509
user311509

Reputation: 2866

Write Simple Stored Procedure

CREATE TABLE Post
(
    postID - PK
    memberID
    title
    thread
    .
    .
    .
    reported             int DEFAULT 0,
    dateCreated          datetime DEFAULT GetDate() NOT NULL
);

I want to write a stored procedure that would raise "reported" field by 1 every-time i execute the procedure. Any idea?

Upvotes: 0

Views: 701

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038890

UPDATE Post SET reported = (reported + 1)

Upvotes: 0

marc_s
marc_s

Reputation: 754538

How about:

CREATE PROCEDURE dbo.UpdateReported(@PostID INT)
AS BEGIN
   UPDATE dbo.Post
   SET Reported = Reported + 1
   WHERE PostID = @PostID
END

You can then call that stored proc with:

EXEC dbo.UpdateReported @PostID = 5

or pass whatever PostID you want to update...

Upvotes: 4

Related Questions