Relatively simple question. I'm trying to perform a statement and check a value prior to adjusting an INSERT value on a firebird trigger. I've seen many examples whereby the new value is assessed and then subsequent statements are executed but none as I want them. Easier to show...
SET TERM ^ ;
CREATE TRIGGER STOP_PREMIX_INSERT_PRODUCEDD FOR PRODUCEDD ACTIVE
BEFORE INSERT OR UPDATE POSITION 0
AS
BEGIN
IF ('SELECT COUNT(*) FROM RECIPESTEPS rs INNER JOIN RECIPES r on r.RECIPEID=rs.RECIPEID INNER JOIN PRODUCEDH h on h.RECIPEID=r.RECIPEID WHERE h.BATCHID=' || new.BATCHID || ' AND ' || new.SEQUENCENO || '=rs.SEQUENCENO AND ' || new.COMMODITYID || '=rs.COMMODITYID AND rs.NONWEIGHED=17;' > 0) then
new.BATCHID=-1;
END^
SET TERM ; ^
I'm trying to validate the existence of a piece of data in another table prior to performing a value change on the new entry.
Normally IF (new.ID = 0) then execute statement 'blah'; would work, but when I write this trigger, it is syntactically accepted but when a value changes I get the following error message:
arithmetic exception, numeric overflow, or string truncation string right truncation At trigger 'STOP_PREMIX_INSERT_PRODUCECEDD' line: 6, col: 5
I might be a semi colon off or this might just not be possible, either way, any help is appreciated.