i’m getting crazy trying to set up an event in my MariaDB.
Basically I have a view (BILANCIO_MESE_CONTABILE) which calculate the current available balance based on expences and entries, starting from the balance available at the begin of the month.
Since months for me start on 15th (which I set in the field “GIORNO” of table “GIORNO_INIZIO_MESE”), I’m trying to create an event that occure every month, when curday() is GIORNO_INIZIO_MESE.GIORNO -1 at 23.59.00, and runs a procedure that inserts a new row in table “BILANCI” where “SALDO_INIZIALE” will be actual “SALDO_FINALE” (final balance from current month).
I keep getting various errors in my event creation; can please someone help to understand what’s wrong or suggest another way to accomplish same thing.
THANKS!!!
EVENT CREATION:
DELIMITER //
CREATE EVENT IF NOT EXISTS `Esegui_AggiornaSaldoIniziale`
ON SCHEDULE EVERY 1 MONTH
STARTS TIMESTAMP(
LAST_DAY(CURDATE() - INTERVAL 1 MONTH) + INTERVAL (SELECT GIORNO - 1 FROM GIORNO_INIZIO_MESE LIMIT 1) DAY
+ INTERVAL '23:59:00' HOUR_MINUTE
)
DO
BEGIN
CALL AGGIORNA_SALDO_INIZIALE();
END //
DELIMITER ;
THIS IS THE PROCEDURE (AGGIORNA_SALDO_INIZIALE) which works as charm when I exec it manually.
INSERT INTO BILANCI (MESE_CONTABILE, SALDO_INIZIALE)
SELECT
MESE_CONTABILE + 1 AS MESE_CONTABILE,
BILANCIO_MESE_CONTABILE.SALDO_FINALE AS SALDO_INIZIALE
FROM
BILANCIO_MESE_CONTABILE;