title: Variable or condition declaration after cursor or handler declaration SQL Statement (mysql)
body: <p>even though i tried many things it still gives me this error (Variable or condition declaration after cursor or handler declaration
  SQL Statement)</p>
  
  <p>the sp must use cursors</p>
  
  <pre><code>CREATE PROCEDURE monthly_sum (IN cardId INT(36), IN monthN INT, OUT sumV float)
  BEGIN
  DECLARE cursor_1 CURSOR FOR
  SELECT SUM(purchased.amountPurchased)
  FROM purchased
  WHERE MONTH(purchased.dateUsed) = monthN AND purchased.purchasedCardId = cardId AND DAY(purchased.dateUsed) &lt;=10;
  
  DECLARE cursor_2 CURSOR FOR
  SELECT SUM(purchased.amountPurchased)
  FROM purchased
  WHERE MONTH(purchased.dateUsed)  = monthN AND purchased.purchasedCardId = cardId AND DAY(purchased.dateUsed) &lt;=20 AND DAY(purchased.dateUsed) &gt;10;
  
  DECLARE cursor_3 CURSOR FOR
  SELECT SUM(purchased.amountPurchased)
  FROM purchased
  WHERE MONTH(purchased.dateUsed) = monthN AND purchased.purchasedCardId = cardId AND DAY(purchased.dateUsed) &gt;20;
  
  DECLARE percentage1, percentage2, percentage3 float default 0;
  
  OPEN cursor_1;
  FETCH cursor_1
  INTO percentage1;
  CLOSE cursor_1;
  
  OPEN cursor_2;
  FETCH cursor_2
  INTO percentage2;
  CLOSE cursor_2;
  
  OPEN cursor_3;
  FETCH cursor_3
  INTO percentage3;
  CLOSE cursor_3;
  SET sumV = percentage1*0.01 + percentage2*0.02 + percentage1*0.03;
  
  SELECT sumV;
  END
  </code></pre>
  
  <p>expected output the sum of 1% of first 10 days, 2% next 10 days, 3% the rest days of the month</p>