title: Stored procedure MySQL 5.5.16
body: <p>So I have in my database a table called "weeks" where I store every weeks of the years like so:</p>
  
  <p><code>table weeks(id, year, num_week, date_min, date_max)</code></p>
  
  <p>So for this week, the line look like this :
  <a href="https://i.stack.imgur.com/n5GF3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n5GF3.png" alt="week 36"></a></p>
  
  <p><strong>Note</strong> : My weeks starts on thursday and ends on Wenesday.</p>
  
  <p>Since it is a pain inserting each weeks line by line, I want to create a stored procedure for this, here's what I came up with :</p>
  
  <pre><code>DELIMITER |
  CREATE PROCEDURE proc_insert_weeks()
  
  BEGIN
  
  SELECT year, num_week, date_min, date_max INTO @year, @num_week, @date_min, @date_max
  FROM weeks
  ORDER BY date_min DESC LIMIT 1;
  
  SET @date_min = DATE_ADD(@date_max INTERVAL 1 DAY);
  SET @date_max = DATE_ADD(@date_min INTERVAL 6 DAY);
  SET @year= YEAR(@date_min);
  
  IF @num_week &lt; 52 THEN SET @num_week = @num_week + 1;
  ELSE SET @num_week = 1;
  END IF;
  
  INSERT INTO weeks (year, num_week, date_min, date_max)
  VALUES (@year, @num_week, @date_min, @date_max);
  
  END |
  
  DELIMITER ;
  </code></pre>
  
  <p>So the idea was to take the last record of the table and add 1 week to the dates, but I can't even make it paste the creation of the procedure. </p>
  
  <p>I get an error right after the SELECT query, can someone help me figure out what I am doing wrong ?</p>