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? Quote Link to comment 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 Quote Link to comment 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 ; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.