need help in the update query table name:- **t_ci**
s39   column_name
        176


i want to have my table like this 

s39    column_name
176     176


But this query works

UPDATE t_ci SET s39=s345  WHERE blueprint_id=1234;


But I dont know the column_name for example s345. This column_name will be the output of a different query

SELECT column_name FROM `t_core_properties` WHERE property_name='Virtual IP Address'


I tried this query.

UPDATE t_ci SET s39=(SELECT column_name FROM `t_core_properties` WHERE property_name='Virtual IP Address')
WHERE blueprint_id=1234;


this comes as

s39    column_name
s360     176


But it adds only the column_name not the value inside that.

I tried using the Mysql User defined Variables

SET @column = (SELECT column_name FROM `t_core_properties` WHERE property_name='Virtual IP Address');
UPDATE t_ci SET s39=@column WHERE blueprint_id IN(SELECT id FROM `t_core_blueprints` WHERE NAME='VMWare VCenter');


I get the same result as before.
The task can be solved using dynamic SQL. Something like:

CREATE PROCEDURE assing_value(propertyname TEXT, blueprintid BIGINT)
BEGIN
SELECT CONCAT('UPDATE t_ci SET s39=', column_name, ' WHERE blueprint_id=', blueprintid)
  INTO @sql
  FROM t_core_properties
  WHERE property_name=propertyname;
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE stmt;
END;


and then

CALL assing_value('Virtual IP Address', 1234);




or the same in plain code:

SET @column := ( SELECT column_name 
                 FROM `t_core_properties` 
                 WHERE property_name='Virtual IP Address');
SET @sql := CONCAT('UPDATE t_ci SET s39=', 
                    @column, 
                   ' WHERE blueprint_id IN (',
                   ' SELECT id',
                   ' FROM `t_core_blueprints`', 
                   ' WHERE NAME=\'VMWare VCenter\')');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE stmt;