SET TERM ^ ;
CREATE OR ALTER trigger TTBPDV_CONFERENCIA_BIUD998 for tbpdv_conferencia
active after insert or update or delete position 998
AS
BEGIN
  IF(INSERTING) THEN
  BEGIN
    IF(NEW.AMBIENTE = 1) THEN
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBPDV_CONFERENCIA', NEW.ID, 2);
    END

  END ELSE
  BEGIN
    IF(OLD.COLABORADOR_ID > 0 AND DELETING)THEN
    BEGIN
       EXECUTE PROCEDURE SPU_SALDO_COLABORADOR(OLD.COLABORADOR_ID);
    END

    IF(OLD.AMBIENTE = 1) THEN
    BEGIN
        EXECUTE PROCEDURE SPI_INTEGRACAO('TBPDV_CONFERENCIA', OLD.ID, 2);
    END
  END

END
^ SET TERM ; ^