June 17, 2013 at 5:52 am
Hi all!
I need to do something upon update/insert of a new record, and as it has to be automatical, i think a trigger is the answer.
As a start, I wrote this:
CREATE TRIGGER [dbo].[SetOtherWorkAccount] ON [dbo].[timeaccountmovement]
AFTER INSERT, UPDATE
AS
IF UPDATE (starttime)
BEGIN
UPDATE timeaccountmovement
SET timeaccountid = 22
WHERE ID IN (SELECT ID FROM inserted)
END
The syntax is ok, its created on table timeaccountmovement.
First problem here is, that i do not know which field is updated - it could be any field in the table, the trigger should fire anyway.
OK, I tried to change the value of starttime on a single record - It should then have a timeaccountid of 22 after that happened.
But nothing happened.
What am I doing wrong?
June 17, 2013 at 6:17 am
edvard 19773 (6/17/2013)
First problem here is, that i do not know which field is updated - it could be any field in the table, the trigger should fire anyway.
You should remove the "IF UPDATE(....)" statement if the trigger must be fired always.
June 17, 2013 at 6:23 am
Thanks - Of cause!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply