Eels Fan
Eels Fan

Reputation: 2063

Trimming Values in a SQL Server database

I have a SQL Server 2008 database. This database has a table with a column named "Name" whose data is not cleaned up. For instance, there are values like 'Hello ', where there is unnecessary whitespace. I want to remove that whitespace from all of the values in the "Name" column. My table looks like this:

MyTable
-------
ID (int)
Name varchar(50)
Description nvarchar(128)

How do I trim up the values in the Name column to remove leading and trailing whitespace?

Thank you!

Upvotes: 2

Views: 1870

Answers (1)

Aaron Bertrand
Aaron Bertrand

Reputation: 280439

Use LTRIM and RTRIM:

UPDATE dbo.MyTable SET Name = LTRIM(RTRIM(Name));

Upvotes: 2

Related Questions