1

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
walangala
  • 231
  • 1
  • 4
  • 15
  • Reset as in turned to NULL? – S3S Aug 24 '16 at 20:06
  • Yes to NULL, sorry for the confusion, I'll edit that. – walangala Aug 24 '16 at 20:10
  • 1
    Why reset data provided by user? Why ask a user to provide data that will be reset? – Serg Aug 24 '16 at 20:10
  • @Serg makes great points, and while i'm not sure why you'd reset something a user inputs, based on what you have given i'd just run a nightly process and avoid the redundant date checks. This question will draw opinions though so a moderator or sql badge user may close it FWIW – S3S Aug 24 '16 at 20:12
  • The webapp dynamically generates a batch of images in a sequence. The user enters a value determines how many images desired in the batch. We would want that value to reset after 24 hours for a new batch each day. – walangala Aug 24 '16 at 20:12
  • Possibly relevant: http://stackoverflow.com/questions/14805742/cronjob-or-mysql-event/14805785#14805785 – Bohemian Aug 24 '16 at 22:32

2 Answers2

1

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

SlavaTT
  • 88
  • 9
0

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

Szörényi Ádám
  • 1,223
  • 13
  • 17