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 9242009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:29:25+00:00 2026-06-18T08:29:25+00:00

I have a use case that requires the creation of a temporary table with

  • 0

I have a use case that requires the creation of a temporary table with a unique name from within a stored procedure. The only way I have found to execute queries with a dynamic table name is to prepare the query:

SET @d=CONCAT('SELECT * FROM table_', case); 
PREPARE q from @d;
EXECUTE q;

This works well enough, but I cannot figure out how to return the result set. Any ideas?

  • 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-06-18T08:29:27+00:00Added an answer on June 18, 2026 at 8:29 am

    You don’t have to do anything extra to return the result set. It’s enough to EXECUTE the prepared query. The result set of that query execution will automatically become the result set of the stored procedure.

    mysql> DELIMITER !!
    mysql> CREATE PROCEDURE p()
        -> BEGIN
        ->  SET @sql := CONCAT('SELECT ', '123 as foo');
        ->  PREPARE q FROM @sql;
        ->  EXECUTE q;
        -> END!!
    mysql> DELIMITER ;
    mysql> CALL p;
    +-----+
    | foo |
    +-----+
    | 123 |
    +-----+
    

    Re your comment: it might be this bug: http://bugs.mysql.com/bug.php?id=20028 which was fixed.
    You may correct the issue by upgrading.

    Noted in 5.0.30 (not 5.0.29), 5.1.13 changelogs.

    With SQL_MODE=TRADITIONAL, MySQL incorrectly aborted on warnings
    within stored routines and triggers.

    Also see https://dba.stackexchange.com/questions/7499/function-returning-no-data-zero-rows-fetched-selected-or-processed-in-mysq

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a use case that requires me to control the deployment (amongst other
I have a use case that requires offline access to google earth. I know
I have the following use case: There's a class called Template and with that
My use case is this... I have a project that has two production branches.
I have a use case where I only need to store certain fields to
At the moment I have a class that requires information from another class, but
i am using requires.js 2.0. I have the following simplified use case: my HTML
I'm just starting to learn AspectJ, and I have use-case for say, User login.
I have following use-case: there are several assemblies decorated with ProtoContract classes and I
I have a use case where I need to call a (non-static) method in

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.