Prepend a string value of a field using SQL Statement

Sometime we would like to add a string in the beginning of a string value, an example is to add a “6” in front of all the contact numbers.

Here the simple way to use SQL statement.

UPDATE thetablename SET thecolumnname=CONCAT(‘6’,thecolumnname);

To make the statement even smarter to ignore value that already have a “6”.

UPDATE thetablename SET thecolumnname=CONCAT(‘6’,thecolumnname)
WHERE thecolumnname NOT LIKE ‘6%’;


Leave A Comment?