Connecting Tech Pros Worldwide Help | Site Map

how to set result of prepare stmt (MYSQL)

Newbie
 
Join Date: Nov 2008
Posts: 7
#1: Nov 26 '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
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,740
#2: Nov 26 '08

re: how to set result of prepare stmt (MYSQL)


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

If so, you should look into Cursors.
Newbie
 
Join Date: Nov 2008
Posts: 7
#3: Nov 26 '08

re: how to set result of prepare stmt (MYSQL)


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