title: Syntax Error for using cursor in a stored procedures
body: <p>I searched the whole website for answer but none of it solve my problem so I'm gona post my error with a new thread.</p>
  
  <p>My code,</p>
  
  <pre><code>DELIMITER $$
  
  USE `DB`$$
  
  DROP PROCEDURE IF EXISTS `GET_Summary`$$
  
  CREATE DEFINER=`connect`@`%` PROCEDURE `GET_Summary`(IN pDateFrom DATE,IN pDateTo DATE)
  
  ROOT:BEGIN
  
      DECLARE pTotal,pShortCode,pSignUp,pUnSub,pJunk INT;
      DECLARE pCOM NVARCHAR(10);
      DECLARE no_more_rows BOOLEAN;
  
      CREATE TEMPORARY TABLE TMOMain
      (GrandTotal INT,ShortCode INT,COM NVARCHAR(10),SignUp INT,UnSub INT, Junk INT);  
  
      DECLARE MoMainCur CURSOR FOR
      SELECT COUNT(*),shortcode,(CASE WHEN ComID= 1 THEN 'A'
      WHEN ComID= 2 THEN 'B' WHEN ComID= 3 THEN 'C' ELSE 'UV' END) AS COM
      FROM tbl_inbox 
      INNER JOIN tbl_keyword ON keywordid = recvkeyword 
      WHERE recvDate &gt;='2011-11-15'  AND recvDate &lt; '2011-11-16' 
      GROUP BY shortcode,COM;
  
      DECLARE CONTINUE HANDLER FOR NOT FOUND
      SET no_more_rows = TRUE;    
  
      OPEN MoMainCur;
  
      read_loop:LOOP
      FETCH MoMainCur INTO pTotal,pShortCode,pCOM ;
  
      INSERT INTO TMOMain
      VALUES
      (pTotal,pShortcode,pCOM ,0,0,0);
      IF no_more_rows THEN
          CLOSE MoMainCur;
          LEAVE the_loop;
  
      END LOOP;
  
      -- CLOSE MoMain;
  
      SELECT * FROM TMOMain;
      END$$
  DELIMITER ;
  </code></pre>
  
  <p>MYSQL version 5.1</p>
  
  <p>ERROR Message:</p>
  
  <blockquote>
    <p>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 MoMainCur CURSOR FOR</p>
  </blockquote>