0
I created the following Rigger, but it has a syntax error that I can’t find.
The error is as follows
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that Corresponds to your Mariadb server version for the right syntax to use near 'on rev_reviews AFTER INSERT AS BEGIN DECLARE @totalItens int DECLARE @Revis' at line 1
Trigger is this one:
CREATE TRIGGER insertReview
on rev_reviews
AFTER INSERT
AS
BEGIN
DECLARE @totalItens int
DECLARE @revisado varchar(4)
DECLARE @countRevisado int
DECLARE @ean varchar(4)
DECLARE @countEan int
select count(1) into @totalItens from rev_reviews where task_id = new.task_id
select @revisado = revisado, @ean = ean_existe from rev_reviews where id = new.id
select @countRevisado = count(1) from rev_reviews where task_id = new.task_id AND Revisado LIKE @revisado
select @countEan = count(1) from rev_reviews where task_id = new.task_id AND ean_existe LIKE @ean;
CASE
WHEN @ean == 'Sim' THEN
CASE
WHEN @revisado == 'Nao'
THEN update rev_tasks set totalItens = @totalItens, totalPen = @countRevisado, totalEan = @countEan where id = new.task_id
WHEN @revisado == 'Sim'
THEN update rev_tasks set totalItens = @totalItens, totalRev = @countRevisado, totalEan = @countEan where id = new.task_id
WHEN @revisado == 'NR'
THEN update rev_tasks set totalItens = @totalItens, totalNr = @countRevisado, totalEan = @countEan where id = new.task_id
WHEN @revisado == 'Aut'
THEN update rev_tasks set totalItens = @totalItens, totalAut = @countRevisado, totalEan = @countEan where id = new.task_id
END
ELSE
CASE
WHEN @revisado == 'Nao'
THEN update rev_tasks set totalItens = @totalItens, totalPen = @countRevisado, totalNEan = @countEan where id = new.task_id
WHEN @revisado == 'Sim'
THEN update rev_tasks set totalItens = @totalItens, totalRev = @countRevisado, totalNEan = @countEan where id = new.task_id
WHEN @revisado == 'NR'
THEN update rev_tasks set totalItens = @totalItens, totalNr = @countRevisado, totalNEan = @countEan where id = new.task_id
WHEN @revisado == 'Aut'
THEN update rev_tasks set totalItens = @totalItens, totalAut = @countRevisado, totalNEan = @countEan where id = new.task_id
END
END
END
From now on, thank you.
Eai, young man. Here at [pt.so] we only accept questions in Portuguese. You can [Dit] your question and translate it to keep it here, but if you prefer you can post the same question on [so].
– Jéf Bueno