How to Remove Space using SQL Statement

Problem: there are leading space and trailing space in the records.

  • leading space
  • trailing space

 

Solution: to remove leading space, e.g. ” EKONOR-25M”, use

UPDATE `Stock_Card-20220218` SET `Item_ID`=TRIM(`Item_ID`) WHERE `Item_ID` LIKE '% ';
BEFORE AFTER

 

Solution: to remove trailing space, e.g. “EKONOR-25M “, SQL statement (“Trim”, “Rtrim”, “Replace”) CANNOT be used. The only way is to delete it manually.