• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 97
  • Last Modified:

Remove space from end of all records in a table

I have a table that contains a lot of usernames. Some of the usernames is stored with a trailing space, and I need to remove this. It means that "johndoe[space]" should be "johndoe".

This SQL returns all records that has usernames ending with space:

SELECT TOP (1000) UserName FROM tblUserVisit WHERE (UserName LIKE '% ')

Open in new window

How can this SQL be modified to remove the trailing space from the usernames?
1 Solution
Haris DjulicCommented:
this will remove spaces in the end... If you want to remove spaces on the begining then you can use TRIM..

set UserName =rtrim(UserName )
where (UserName LIKE '% ')

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now