Reputation: 10354
I want to write a trigger that should execute beginning of the every date based on the server datetime. In that I want to update one table such as follow:
UPDATE STR_IRSHeader SET StatusID = 4
WHERE GETDATE()>ExpiryDate.
How to write a trigger for this?
Upvotes: 1
Views: 8512
Reputation: 23624
You don't need a trigger, but job.
See http://msdn.microsoft.com/en-us/library/ms191439.aspx
Upvotes: 2
Reputation: 432311
Triggers are not scheduled by time.
SQL triggers are invoked by actions that change data (UPDATE, INSERT, DELETE, ALTER etc)
You should use a SQL Server Agent job to run the SQL you want.
Your SQL can be wrapped in a stored procedure too: this allows you to run it manually and have the exact code in one place: less chance of mistakes or multiple versions of the code
Upvotes: 1
Reputation: 24334
You could create a shell script and then set up a cron job to run every day at midnight?
Upvotes: 1