From: Peter Brawley Date: October 4 2011 9:27pm Subject: Re: Variables in stored procedure List-Archive: http://lists.mysql.com/mysql/225918 Message-Id: <4E8B7A3E.2080800@earthlink.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 10/4/2011 4:20 PM, Adam Gerson wrote: > I am getting the error that "TABLENAME" does not exist. How do I get > it to substitute the value stored in TABLENAME, and not the literal > string? See the manual page for PREPARE. PB ----- > > begin > > declare v_max int unsigned default 1; > declare v_counter int unsigned default 21; > declare TABLENAME text; > > start transaction; > while v_counter <= v_max do > SET TABLENAME = CONCAT('wp_',v_counter, '_options'); > INSERT INTO TABLENAME VALUES ('309', '0', 'statpress_mincap', > 'edit_posts', 'yes'); > set v_counter=v_counter+1; > end while; > commit; > END > > > Thanks, > Adam >