0

Whenever the field sync is updated without the flag being YES I need to set that field to NULL.

CREATE TRIGGER my_trigger FOR customers
AFTER UPDATE
as
BEGIN
if(new.sync <> 'YES')
  then new.sync = NULL;
end

But I keep receiving the error:

Dynamic SQL Error SQL error code = -104 Unexpected end of command - line 6, column 26

I believe line 6 is then new.sync = NULL? I thought the problem might be the use of ; but it's not, because if I remove it then it gives the same error but in the line 7.

Linesofcode
  • 5,327
  • 13
  • 62
  • 116

1 Answers1

4

Solved.

Some code was missing but besides that also the logic. I needed to used BEFORE and not AFTER.

SET TERM !; 
CREATE TRIGGER my_trigger FOR customers 
BEFORE UPDATE 
POSITION 0 
AS BEGIN 
    IF(new.sync <> 'YES') THEN BEGIN 
        new.sync = NULL; 
    END
END;
Linesofcode
  • 5,327
  • 13
  • 62
  • 116