mysql - How to get variable value as table name in select statement -
set project_list_val=concat(project_number_val,'_list'); insert test (manthan_panel_id) select manthan_panel_id project_list_val project_number_val='9';
in insert statement there variable named 'project_list_val' consist of table name concated in above step. statement not taking content of variable table name instead taking 'project_list_val' table name , giving table not found error.
any suggestions?
by default you cannot parameterized table names , column names need create dynamic sql that,
set @project_list_val = concat(project_number_val, '_list'); set @projnum = 9; set @sql = concat(' insert test (manthan_panel_id) select manthan_panel_id ', @project_list_val, ' project_number_val = ?'); prepare stmt @sql; execute stmt using @projnum; deallocate prepare stmt;
mysql stored-procedures
No comments:
Post a Comment