Click here to Skip to main content
15,891,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currently facing an issue in concatenating "NEW" Keyword with column names using concat function..

SQL
 SET @values =
(SELECT GROUP_CONCAT(CONCAT_WS('.','new', table1.col) SEPARATOR ',')
FROM tbale1, table2, table3, table4
WHERE table3.table3_id = '001'
AND table3.id = table4.table3_id
AND table4.col = table2.col
AND table1.id = table2.table1_id
ORDER BY table2.col);

ON execution, instead of replacing the values for NEW keyword(last inserted records/values) it just returns as NEW.col1,NEW.col2,NEW.col3 instead of their assigned values.please help me out with this..

desired output is SELECT @var ='aa','bb','cc','ccc'; But current output is SELECT @var = NEW.col1,NEW.col2,NEW.col3,NEW.col4;
Posted
Updated 16-Nov-15 2:20am
v2

1 solution

It looks like you are trying to create a SQL statement dynamically.
In MySQL this is called Prepared Statements and you can look up the reference manual here:
13.5 SQL Syntax for Prepared Statements[^]
Sometimes the MySQL documentation doesn't provide the easiest to understand examples, so here is another link: MySQL Prepared Statement[^]

I hope this helps you on the way.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900