Jump to content

Concat trigger separators


poodleinplad

Recommended Posts

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

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 ;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.