I'm having problems with creating a trigger in mysql, but I do not know why it's causing me an error. The table in which I want to insert once the trigger is activated is the following:
CREATE TABLE 'reportes' (
'id' int(11) NOT NULL,
'tipoCambio' varchar(10) NOT NULL,
'fechaCambio' date NOT NULL,
'rut' varchar(10) NOT NULL,
'nombre' varchar(20) NOT NULL,
'idCredencial' int(11) NOT NULL,
'reserva' varchar(80) NOT NULL,
'horario' varchar(20) NOT NULL
)
And the trigger is this:
DELIMITER //
CREATE TRIGGER agregaReserva AFTER INSERT ON reserva
FOR EACH ROW
BEGIN
DECLARE tRut VARCHAR(10);
SELECT u.rut INTO @tRut FROM reserva r
INNER JOIN credencial c ON r.idCredencial = c.id
INNER JOIN usuario u ON c.id = u.idCredencial
WHERE r.id = NEW.id;
DECLARE tFechaAct DATE;
SELECT CURDATE() INTO @tFechaAct;
DECLARE tNombre VARCHAR(20);
SELECT u.nombre INTO @tNombre FROM reserva r
INNER JOIN credencial c ON r.idCredencial = c.id
INNER JOIN usuario u ON c.id = u.idCredencial
WHERE r.id = NEW.id;
DECLARE tReserva VARCHAR(80);
SELECT CONCAT(tr.tipo, ' Nº ', tr.numeroDispositivo) AS reserva
INTO @tReserva FROM tiporeserva tr
INNER JOIN reserva r ON tr.id = r.idTipoReserva
WHERE r.id = NEW.id;
DECLARE tHorario VARCHAR(20);
SELECT CONCAT(h.horaComienzo, ' - ', h.horaFin)
INTO @tHorario FROM horario h
INNER JOIN reserva r ON h.bloque = r.bloqueHorario
WHERE r.id = NEW.id
INSERT INTO 'reportes'('tipoCambio', 'fechaCambio', 'rut', 'nombre', 'idCredencial', 'reserva', 'horario') VALUES ('Reserva', @tFechaAct, @tRut, @tNombre, NEW.idCredencial, @tReserva, @tHorario);
END //
Finally, the error he mentions is:
Error MySQL has said:
1064 - Something is wrong in its syntax near 'DECLARE tFechaAct DATE; SELECT CURDATE () INTO @tFechaAct;
DECLARE tName VA 'on line 11 Open new phpMyAdmin window