Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem is not solved yet (Re:-prepare stmt)

Newbie
 
Join Date: Nov 2008
Posts: 7
#1: Nov 28 '08
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

Expand|Select|Wrap|Line Numbers
  1.   CREATE PROCEDURE `sp_countrows`(in_table_name varchar(30))
  2.   READS SQL DATA
  3.   BEGIN
  4.   SET @s = CONCAT('SELECT sum(QuotaUsage) AS "', in_table_name, '(SUM)" FROM ', in_table_name);
  5.   PREPARE stmt FROM @s;
  6.   EXECUTE stmt;
  7.   END
  8.  
-----------------------------------------------------------------------------------------
Atli
Moderator

So you want to use the results of the query in the procedure?
If so, you should look into Cursors.

-----------------------------------------------------------------------------------------
pankaj
newbie

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.

Reply