Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6796213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:26:24+00:00 2026-05-26T18:26:24+00:00

I have a stored proc which inserts rows from a view with ranks into

  • 0

I have a stored proc which inserts rows from a view with ranks into a temporary table.

The temp table is created before I run a cursor loop that inserted values, and SELECT’ed after the loop is done.

However when I CALL medianMessagesPerWeek(); I get an “Error Code : 1329 No data – zero rows fetched, selected, or processed.”

If I create the table as a MYISAM table I can manually select the table and confirm that data has been inserted but the stored proc will still give me nothing.

Am I missing something here?

DELIMITER $$

USE `yongopal_metrics`$$

DROP PROCEDURE IF EXISTS `medianMessagesPerWeek`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `medianMessagesPerWeek`()
BEGIN
    DECLARE done INT DEFAULT FALSE;
    DECLARE tempJoinWeek, tempActiveWeek, rank INT DEFAULT 0;
    DECLARE joinWeek, activeWeek, memberNo, messages INT;
    DECLARE cur CURSOR FOR SELECT * FROM cohortMessagesPerMemberPerWeek;

    DROP TEMPORARY TABLE IF EXISTS medianMessagesPerWeek;
    CREATE TEMPORARY TABLE medianMessagesPerWeek
    (
        joinWeek INT,
        activeWeek INT,
        memberNo INT,
        messages INT,
        rank INT
    ) ENGINE=MEMORY;    

    OPEN cur;

    read_loop: LOOP
        FETCH cur INTO joinWeek, activeWeek, memberNo, messages;
        IF done THEN
            LEAVE read_loop;
        END IF;

        IF tempJoinWeek = joinWeek AND tempActiveWeek = activeWeek THEN
            SET rank = rank + 1;
        ELSE
            SET tempJoinWeek = joinWeek;
            SET tempActiveWeek = activeWeek;
            SET rank = 1;
        END IF;
        INSERT INTO medianMessagesPerWeek VALUES (joinWeek, activeWeek, memberNo, messages, rank);
    END LOOP;

    CLOSE cur;

    SELECT * FROM medianMessagesPerWeek;
    DROP TEMPORARY TABLE IF EXISTS medianMessagesPerWeek;
    END$$

DELIMITER ;

EDIT

here is what cohortMessagesPerMemberPerWeek looks like

DELIMITER $$

USE `yongopal_metrics`$$

DROP VIEW IF EXISTS `cohortMessagesPerMemberPerWeek`$$

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `cohortMessagesPerMemberPerWeek` AS 
SELECT
  WEEK(`m`.`regDatetime`,0) AS `joinWeek`,
  WEEK(`cd`.`sendDate`,0) AS `activeWeek`,
  `m`.`memberNo` AS `memberNo`,
  COUNT(0)       AS `messages`
FROM (`yongopal`.`chatData` `cd`
   JOIN `yongopal`.`members` `m`
     ON ((`cd`.`sender` = `m`.`memberNo`)))
GROUP BY WEEK(`m`.`regDatetime`,0),WEEK(`cd`.`sendDate`,0),`m`.`memberNo`
ORDER BY WEEK(`m`.`regDatetime`,0),WEEK(`cd`.`sendDate`,0)$$

DELIMITER ;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:26:25+00:00Added an answer on May 26, 2026 at 6:26 pm

    Looks like you’re missing a not found handler for your cur cursor. This is necessary to set your done boolean to true when the fetch statement no longer returns any rows (and hence you have reached the end of the dataset returned by the cursor declaration).

    Give this a try:

    DELIMITER $$
    
    USE `yongopal_metrics`$$
    
    DROP PROCEDURE IF EXISTS `medianMessagesPerWeek`$$
    
    CREATE DEFINER=`root`@`localhost` PROCEDURE `medianMessagesPerWeek`()
    BEGIN
        DECLARE done INT DEFAULT FALSE;
        DECLARE tempJoinWeek, tempActiveWeek, rank INT DEFAULT 0;
        DECLARE joinWeek, activeWeek, memberNo, messages INT;
        DECLARE cur CURSOR FOR SELECT * FROM cohortMessagesPerMemberPerWeek;
    
        declare continue handler for not found set done := true; 
    
        DROP TEMPORARY TABLE IF EXISTS medianMessagesPerWeek;
        CREATE TEMPORARY TABLE medianMessagesPerWeek
        (
            joinWeek INT,
            activeWeek INT,
            memberNo INT,
            messages INT,
            rank INT
        ) ENGINE=MEMORY;    
    
        OPEN cur;
    
        read_loop: LOOP
            FETCH cur INTO joinWeek, activeWeek, memberNo, messages;
            IF done THEN
                LEAVE read_loop;
            END IF;
    
            IF tempJoinWeek = joinWeek AND tempActiveWeek = activeWeek THEN
                SET rank = rank + 1;
            ELSE
                SET tempJoinWeek = joinWeek;
                SET tempActiveWeek = activeWeek;
                SET rank = 1;
            END IF;
            INSERT INTO medianMessagesPerWeek VALUES (joinWeek, activeWeek, memberNo, messages, rank);
        END LOOP;
    
        CLOSE cur;
    
        SELECT * FROM medianMessagesPerWeek;
        DROP TEMPORARY TABLE IF EXISTS medianMessagesPerWeek;
        END$$
    
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following stored proc which uses a temp table to bulk import
I have a stored procedure (see below) which inserts data into a physical table
I have a Stored proc which returns 6 select statement results. I'm trying to
I am using SQL 2000. I have a stored proc, spGetApplicantList , which cannot
I have a VB.Net function which executes a Oracle Stored Proc and returns a
I have a stored proc in SQL Server 2005, which looks like the following
Environment: SQL Server 2005 I have a stored proc which receives comma separated value
We have a stored proc where it returns a record which is of type
I have a SQL Server 2005 stored proc which returns two result sets which
I have a function Split which I am calling in a stored proc with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.