Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to remove an extra space from a string?

Author  Topic 

fawadafr
Starting Member

47 Posts

Posted - 2011-02-28 : 17:08:47
Hello,

How can I remove extra spaces from a text string such as name or address in the database?

I believe SUBSTRING function is a good way to go but wanted to hear you input on this.

Thank you,

--
Fawad Rashidi
Web Developer
www.fawadafr.com

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-02-28 : 17:18:55
There's an RTRIM function that removes trailing spaces, and LTRIM removes leading spaces. The REPLACE function can remove all spaces in a string.
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-01 : 10:27:29
and Ltrim function for leading spaces of a string

Cheers
MIK
Go to Top of Page

fawadafr
Starting Member

47 Posts

Posted - 2011-03-01 : 11:23:20
Thank you very much for the quick reply. I believe the REPLACE() function would be best to search for every two spaces in a string and replace it with a single space. Unless, there is a better way...

--
Fawad Rashidi
Web Developer
www.fawadafr.com
Go to Top of Page
   

- Advertisement -