how to set result of prepare stmt (MYSQL)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankaj17
    New Member
    • Nov 2008
    • 7

    how to set result of prepare stmt (MYSQL)

    hello everyone,

    MYSQL query ............

    how to set prepare stmt result in variable

    i have written prepare stmt in store procedure and i want to set result of prepare stmt in variable

    Code:
    CREATE PROCEDURE `sp_countrows`(in_table_name varchar(30))
    READS SQL DATA
    BEGIN
    SET @s = CONCAT('SELECT sum(QuotaUsage) AS "', in_table_name, '(SUM)" FROM ', in_table_name);
    PREPARE stmt FROM @s;
    EXECUTE stmt;
    END
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    So you want to use the results of the query in the procedure?

    If so, you should look into Cursors.

    Comment

    • pankaj17
      New Member
      • Nov 2008
      • 7

      #3
      can u explain me with example. I haven't used the cursor yet.
      I am new in mysql.
      so please tell me with example how to get the prepare stmt result using cursor........

      I have seen example of cursor in mysql site. but they haven't used the prepare stmt.

      i am passing table name as a parameter to procedure because the tables are generated dynamically after every month (that kind of script is written on linux OS). so the table name is not fix.

      Comment

      Working...