Tuesday, 8 November 2011

pass table name as variable in stored procedure in mysql


CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_getdataforexport`(in tablename varchar(100),in tblcityname varchar(100))
BEGIN
    
      set @citycode= (select citycode from ea_citymaster where cityname=tblcityname);    
      SET @s = CONCAT('select * from ', tablename, ' where CityCode=''',@citycode,'''');
      PREPARE stmt FROM @s;
      EXECUTE stmt; 
    END$$

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger