mysql - Stored Procedure - Need to use the result of a SELECT statement -


the following stored procedure return result column noofarticles correct total amount.

delimiter //  create definer=`root`@`localhost` procedure `sp_membersarea`(in reqdtable varchar(30), in scannerid int, in memberid int) begin declare noofarticles int(11);   set @sql_text = concat("select count(*) noofarticles t_annualdetails scannerid = ", scannerid); prepare stmt @sql_text; execute stmt;  deallocate prepare stmt;  end // delimiter ; 

so-far-so-good. here problem. able use 'result' in query within same stored procedure, don't know how achieve it. work this:

set @noofarticles = noofarticles;     set @sql_text = concat("update ", reqdtable, " set scan = ", @noofarticles, " memberid = ", memberid); prepare stmt @sql_text; execute stmt; 

obviously, doesn't work, 'result' (noofarticles) placed in variable (i.e. @noofarticles), , use variable (@noofarticles) inside update statement.

i've been on day no success. i'd grateful guidance. thanks.

it's into, not as

delimiter //  create definer=`root`@`localhost` procedure `sp_membersarea`(in reqdtable varchar(30), in scannerid int, in memberid int) begin declare noofarticles int(11);  /*----------------------------------here-v--into-instead-of-as-----------------*/ set @sql_text = concat("select count(*) noofarticles t_annualdetails scannerid = ", scannerid); prepare stmt @sql_text; execute stmt;  deallocate prepare stmt;  set @noofarticles = noofarticles;     set @sql_text = concat("update ", reqdtable, " set scan = ", @noofarticles, " memberid = ", memberid); prepare stmt @sql_text; execute stmt;  /*you can use parameters, not tablename*/ set @sql_text = concat("update ", reqdtable, " set scan = ? memberid = ?"); prepare stmt @sql_text; execute stmt using noofarticles, memberid;  end // delimiter ; 

edit:

delimiter //  create definer=`root`@`localhost` procedure `sp_membersarea`(in reqdtable varchar(30), in scannerid int, in memberid int) begin  set @sql_text = concat("select count(*) @noofarticles t_annualdetails scannerid = ", scannerid); prepare stmt @sql_text; execute stmt;  deallocate prepare stmt;  /*you can use parameters, not tablename*/ set @sql_text = concat("update ", reqdtable, " set scan = ? memberid = ?"); prepare stmt @sql_text; execute stmt using @noofarticles, memberid;  end // delimiter ; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -