We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

SQL Server remove all spaces in data

Medium Priority
2,182 Views
Last Modified: 2011-08-18
I get "extracted date" that has a field that end users place their zipcodes in.

Unfortunately there are a lot of records with spaces in the zipcode field WITH the zipcode

'     99032'
' 99033       '
'99034'

I need to strip ALL spaces.  Is there an update I can run?
Comment
Watch Question

Commented:
update table
set field = rtrim(ltrim(field))

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT
Commented:
Hi lrbrister,

try something like this:
UPDATE
  YOURTABLE
SET
  zipcode = REPLACE(zipcode, ' ', '')
CERTIFIED EXPERT

Commented:
Hi lrbrister,

Note my solution will remove spaces from the middle of zipcodes as well as either end - if you do not want this use gpompe's solution
Larry Bristersr. Developer

Author

Commented:
Hey guys...both are great.  Splitting the points with a tiny bit more to gpompe:
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.