poodleinplad Posted June 26, 2012 Share Posted June 26, 2012 I'm trying to create a trigger that concates several columns into one but something is wrong with "the separators". Trigger example: DELIMITER $$ CREATE TRIGGER combine_path BEFORE INSERT ON table_x FOR EACH ROW BEGIN SET NEW.comb_path = CONCAT(NEW.valueone, '_', NEW.valuetwo, '_', NEW.valuethree); END $$ DELIMITER ; I want the results to be 1_2_3 but with this trigger I only get 1 unless I remove the underscore. What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/264792-concat-trigger-separators/ Share on other sites More sharing options...
mikosiko Posted June 26, 2012 Share Posted June 26, 2012 read .... http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat Link to comment https://forums.phpfreaks.com/topic/264792-concat-trigger-separators/#findComment-1357041 Share on other sites More sharing options...
poodleinplad Posted June 26, 2012 Author Share Posted June 26, 2012 Thanks, I finally got it. I think I was somewhat stupid. The target column was "INT" so I guess it didn't want an underscore! Anyhow, this is the trigger that finally did it. DELIMITER $$ CREATE TRIGGER combine_path BEFORE INSERT ON table_x FOR EACH ROW BEGIN SET NEW.comb_path = CONCAT_WS('_',NEW.valueone,NEW.valuetwo,NEW.valuethree); END $$ DELIMITER ; Link to comment https://forums.phpfreaks.com/topic/264792-concat-trigger-separators/#findComment-1357067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.