title: MySQL Trigger : #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
body: <p>I have problems creating triggers in MySQL 5.1.73
  This is de syntax:</p>
  
  <pre><code>DELIMITER $$
  CREATE TRIGGER `discount2` 
  BEFORE 
  INSERT ON `order_item` 
  FOR EACH ROW 
  DECLARE alumno INT;
  DECLARE profesor INT;
  DECLARE dto decimal(10,2);
  SET @alumno := (SELECT user_id from `order` where `order`.id = NEW.order_id)
  SET @profesor := (SELECT id_profesor from user where user.id = @alumno)
  SET @dto := (SELECT descuento from descuentos
  join user on descuentos.id_profesor = user.id
  join producto on producto.familia=descuentos.familia
  where producto.id = NEW.product_id and user.id = @profesor)
  
  SET.NEW.descuento = SELECT CAST((((@dto)*(NEW.pvp))/100) AS DECIMAL(10,2))
  $$
  DELIMITER ;
  </code></pre>
  
  <p>But there is some error...</p>
  
  <pre><code>#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE alumno INT;
  DECLARE profesor INT;
  DECLARE dto decimal(10,2);
  SET @alu' at line 5
  </code></pre>
  
  <p>Someone can help me, please?
  Thanks u</p>