0

I want to create trigger that will update the record. The situation is like:

I have one column named CheckInDateTime and one more named Status. If the administrator is not able to update the Status within 30 minutes of CheckInDateTime I want to update the Status column of that particular row.

How can I update that particular row?

6
  • Can you clarify what you mean by "if administrator not able to update the Status after half hour of checkintime. then I want to update the column of that perticular row" - it is unclear what you are attempting to do.
    – Hannah Vernon
    Commented Nov 14, 2013 at 5:33
  • I will tell you exact what I'm want to do, If first time status field has value PendingForApproval. If admin is not able to approve that perticular record within 30 min, then i want to update that perticular record's value to be ForcefullyClosed. How can I do ? Commented Nov 14, 2013 at 5:57
  • Which DBMS are you using?
    – Hannah Vernon
    Commented Nov 14, 2013 at 5:58
  • MsSqlServer 2008 Commented Nov 14, 2013 at 6:06
  • 1
    You dont need a trigger for this. As Max pointed out, you have to use sql agent to schedule it.
    – Kin Shah
    Commented Dec 14, 2013 at 16:23

1 Answer 1

1

Create a task in SQL Server Agent that runs a stored procedure once every minute that updates the affected rows.

For instance, something like this might work:

CREATE PROCEDURE UpdateRows
AS
BEGIN
    DECLARE @Cutoff DATETIME;
    SET @Cutoff = DATEADD(mi, -30, GETDATE());
    UPDATE MyTable
    SET Status = 'ForcefullyClosed'
    WHERE CheckInDateTime < @Cutoff AND Status IS NULL;
END;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.