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
 General SQL Server Forums
 New to SQL Server Programming
 Trim spaces in middle

Author  Topic 

Inno
Starting Member

33 Posts

Posted - 2006-06-20 : 09:53:42
In a table I have a coulmn of postal-codes where there is a space in the middle of the postcode. How do I do to trim them away?

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-06-20 : 09:55:06
select replace('SE16 7TG', ' ', '')


Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

Inno
Starting Member

33 Posts

Posted - 2006-06-20 : 09:56:57
I dont understand. Each postal code in the column has a space in it and I have to remove it from every post. I cannot specify all and use replace.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-20 : 10:06:09
Select replace(yourColumn,' ','') from yourTable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Inno
Starting Member

33 Posts

Posted - 2006-06-20 : 10:16:04
Ow thnx, didnt know one could specify an entire column there in the replace statement.

But it doesnt solve my problem :( I want the spaces to get trimmed away from the table column and not just get a new list without them.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-20 : 10:18:34
Use update

Update yourTable set yourColumn=replace(yourColumn,' ','')

Also,Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Inno
Starting Member

33 Posts

Posted - 2006-06-20 : 10:43:18
Man it is too hot...thanks alot works fine :)
Go to Top of Page
   

- Advertisement -