SET TERM ^ ;

CREATE trigger ttbpdv_cfe_item_b05i for tbpdv_cfe_item
active before insert position 5
AS
BEGIN
    /* DEFINIR ITEM PROMOCIONAL DE ACORDO COM O PRE-PEDIDO, CASO EXISTA */
    IF(COALESCE(NEW.CONFERENCIA_ITEM_ID, 0) > 0) THEN
    BEGIN
        NEW.PROMOCIONAL = COALESCE((SELECT FIRST 1 T.PROMOCIONAL FROM TBPDV_CONFERENCIA_ITEM T WHERE T.ID = NEW.CONFERENCIA_ITEM_ID), 0);
    END
END
^

SET TERM ; ^

