Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trim on a table column in SQL Server 2005

I have a table called Examination and a column Name. In this Name column lot of values are with leading spaces and trailing spaces. I want to know how to update this column so that there are no spaces in the values.

like image 315
Naveen Avatar asked Apr 27 '26 19:04

Naveen


2 Answers

If you want to fix the existing data:

UPDATE Examination SET Name = RTRIM(LTRIM(Name))

Generally in your application layer you should "clean" the data before it goes into the database.

The RTRIM function will remove trailing space on the right, and LTRIM will remove it on the left.

In C#, you can trim both the left and the right using the Trim method on string, which will return a new string trimmed.

like image 151
vcsjones Avatar answered Apr 29 '26 08:04

vcsjones


UPDATE Examination SET [Name] = LTRIM(RTRIM([Name]))
like image 23
Chris E Avatar answered Apr 29 '26 09:04

Chris E



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!