Reputation: 1210
I have the next code that cannot solve.
The line Set @Numero=... Returns error
Begin
Declare @Numero INT;
SET @Numero= SELECT id from visita where cliente_id=OLD.cliente_Id order by id desc limit 1;
INSERT INTO HistoricoMaquina
SET
Precio=OLD.Precio,
fecha = NOW(),
Visita_Id=@Numero;
End;
I have tried
select @Numero=Id from visita where cliente_id=1 order by id desc limit 1;
Also
select @Numero=Id from visita where cliente_id=1 order by id desc limit 1;
But none of them works, Any Idea?
Upvotes: 0
Views: 26
Reputation: 49410
This works if your Select query gives an answer
INSERT INTO HistoricoMaquina (Precio,fecha,Visita_Id)
SELECT OLD.Precio, NOw(),id from visita where cliente_id=OLD.cliente_Id order by id desc limit 1;
Upvotes: 1