Simon Arnold Simon Arnold - 4 months ago 7
SQL Question

Remove last char if it's a specific character

I need to update values in a table by removing their last char if they ends with a

+


Example:
John+Doe
and
John+Doe+
should both become
John+Doe
.

What's the best way to achieve this?

Answer
UPDATE table 
SET field = SUBSTRING(field, 1, CHAR_LENGTH(field) - 1) 
WHERE field LIKE '%+'
Comments