Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL syntax that equals to Trim in excel 2

Status
Not open for further replies.

devon59

Technical User
Nov 30, 2005
18
US
Could anyone tell me what is the sql syntax that gives me a similar result as Trim in excel? Basically, I have the data that has space in the middle and I want to get rid of that space. e.g. 111 111 111 and I want to get rid of spaces between the ones.
Thank you
 
So, you want '111 111 111' to become '111111111' ?

SQL has a replace function that you can use. You can look it up in Books On line.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thank you George. Please bare with me but I don't want to replace a space but just get rid of it. Isn't Replace used when I want to replace something?
 
Use Replace(<your col or string>, ' ', '')

Notice you are looking for a space ' ', and replacing it with nothing ''. The spaces will be removed.

Jim
 
Yes. But, you can replace a space character with nothing.

Example
Code:
Declare @Temp VarChar(20)
Set @Temp = '111 111 111'

Select @Temp, Replace(@Temp, ' ', '')

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Devon59

this will take out the spces. Just run it in you SQL editor and you'll see.



SELECT REPLACE('abc defg hicde',' ','')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top