ALTER TABLE TBGRUPOCONTA
ADD STATUS INTEGER;

CREATE TRIGGER TTBGRUPOCONTA_B01I FOR TBGRUPOCONTA
ACTIVE BEFORE INSERT POSITION 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( NEW.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'Registro Incluido';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBGRUPOCONTA',NEW.ID, HISTORICO);
    END
end;

CREATE TRIGGER TTBGRUPOCONTA_B01D FOR TBGRUPOCONTA
ACTIVE BEFORE DELETE POSITION 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( OLD.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||'Registro Excluido';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBGRUPOCONTA',old.ID, HISTORICO);
    END
end;

CREATE TRIGGER TTBGRUPOCONTA_B01U FOR TBGRUPOCONTA
ACTIVE BEFORE UPDATE POSITION 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( OLD.DESCRICAO <> NEW.DESCRICAO) THEN
    BEGIN
        HISTORICO = HISTORICO||'Descricao:'|| OLD.DESCRICAO||'->'||NEW.DESCRICAO;
    END
    IF ( OLD.STATUS <> NEW.STATUS) THEN
    BEGIN
        HISTORICO = HISTORICO||',Status:'|| OLD.STATUS||'->'||NEW.STATUS;
    END
    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBGRUPOCONTA',NEW.ID, HISTORICO);
    END
end;