I need a trigger that rolls back an update of record, if that record update changes the value of a field to another value.
ALTER TRIGGER [dbo].[TimezoneRollback]
DECLARE @i int
SET @i = 0
Select @i = count(u.userid)
FROM UserSettings AS u JOIN inserted AS i ON i.UserId = u.UserId
WHERE i.TimeZoneCode != u.TimeZoneCode
IF(@i > 0)
So I wrote a "FOR UPDATE" Trigger, which checks the current value of the timezone and compares that to the value of the timezone in the INSERTED table.
When those values don't match (for me this means that the update included a different timezone than the current one), a rollback happens.
Unfortunately this doesn't work. The variable @i always is 0, no matter if I execute an update with a different timezone.
Can anyone help me?