Answer the question
In order to leave comments, you need to log in
How to pass mysql procedure argument to column name?
There is a procedure:
CREATE DEFINER = 'root'@'%'
PROCEDURE db.admin_change_product(
IN infield varchar(255),
IN invalue varchar(255),
IN inidProduct int
)
BEGIN
UPDATE goods g SET g.infield = invalue WHERE g.id = inidProduct;
END
Unknown column 'g.inField' in 'field list'
UPDATE goods g SET `inField` = inValue WHERE `id` = inIdProduct;
Answer the question
In order to leave comments, you need to log in
You are essentially trying to make a dynamic query (specify the names of columns, tables, etc. at runtime), but as you wrote it will not work. In MySQL, the only way to create dynamic queries is to collect them as strings and then execute them like this:
SET @myquery := CONCAT("UPDATE goods SET ", infield, " = ", invalue, " WHERE id = ", inidProduct);
PREPARE myquery FROM @myquery;
EXECUTE myquery;
DEALLOCATE PREPARE myquery;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question