I have some problems with my trigger.
On my transactions table I can't allow any rows to be inserted which are cancelled.
Any transaction can be Scheduled
, Done
or Cancelled
.
If you insert a cancelled transaction, my trigger should check the date of transaction and if was before the actual date (GETDATE()
) it's Done
, and if its after the actual date is Scheduled
.
I performed and it worked, but it change the old records not only the inserted row.
CREATE OR ALTER TRIGGER t2222
ON Transacoes
AFTER INSERT
AS
BEGIN
UPDATE TRANSACOES
SET ESTADO = 'Done'
FROM inserted i
WHERE (i.ESTADO = 'Cancelada' AND i.DATA_DA_TRANSACAO < GETDATE())
UPDATE TRANSACOES
SET ESTADO = 'Scheduled'
FROM inserted i
WHERE (i.ESTADO = 'Cancelada' AND i.DATA_DA_TRANSACAO >= GETDATE())
END
GO