walangala
walangala

Reputation: 241

Best Practice for a scheduled stored procedure

I have a stored procedure that takes user input from a webform and updates a database.

CREATE TABLE AccountTable
(
   RowID int IDENTITY(1, 1),
   AccountID varchar(2),
   AccountName varchar(50),
   SeqNum int,
   SeqDate datetime
 )

CREATE PROCEDURE [ACCOUNTTABLE_UPDATE]
(
  @SeqNum int,
  @SeqDate datetime,
  @Account_ID varchar(2)
)
AS 
    SET NOCOUNT ON
BEGIN
    UPDATE AccountTable
    SET SeqNum = @SeqNum, SeqDate = @SeqDate
    WHERE AccountID = @AccountID
END

Each time the user runs the webapp, the table updates the SeqNum and SeqDate columns. I would like to have the SeqNum column reset after ever 24 hours to NULL. Would just putting in the stored procedure checking if the current date is greater than the dates column be ideal or implementing a scheduled task?

Upvotes: 1

Views: 114

Answers (2)

If you really want to this I think you should use SQL Agent for scheduling.

Upvotes: 0

SlavaTT
SlavaTT

Reputation: 88

Simply try running your SP as Sql Agent service's task.

Upvotes: 1

Related Questions