I'm trying to create a MySql query which will construct a string using the CONCAT function within 2 loops.
I'm wondering if a string can be used both as a variable and a reference to a field in a table?
My code so far is below, which is returning some syntax error near the UPDATE line:
...
WHILE x <= 5 DO
WHILE y <= 3 DO
SELECT @str_data = CONCAT(str,'data_',x);
SELECT @str_data = CONCAT(str,'_',y);
SELECT @variable:= @str_data FROM sometable WHERE id = '@counter + y';
UPDATE anothertable SET @str_data = @variable WHERE id = '@counter + y';
SET y = y + 1;
END WHILE;
SET x = x + 1;
SET @counter = counter + 3;
END WHILE;
I've checked all variables are set.
On a side note I may not be using the concat correctly, since I saw it being used differently in multiple examples. I intend for the format to end up as: 'data_x_y'. (By adding the '_y' to the end of the current string. := ?)