Linesofcode
Linesofcode

Reputation: 5903

Trigger on Update Firebird

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.

Upvotes: 0

Views: 1197

Answers (1)

Linesofcode
Linesofcode

Reputation: 5903

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;

Upvotes: 4

Related Questions