Table of Contents

Microsoft - Microsoft SQL Server - SQL - Find - Find Leading or Trailing Spaces

Find Leading and Trailing spaces

SELECT * FROM #Temp 
WHERE name LIKE '% ' --Will provide us values with Trailing space/s
OR name LIKE ' %'     --Will provide us values with leading Space/s

Update the records and remove leading and trailing spaces

UPDATE #Temp
SET Name=LTRIM(RTRIM(Name))
WHERE name LIKE '% ' 
OR name LIKE ' %'