SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 outputting results; removing '-' from zip codes
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

wleonard
Starting Member

USA
30 Posts

Posted - 09/10/2013 :  16:11:31  Show Profile  Reply with Quote
I'm trying to construct a query that takes results from a table (zip codes, essentially) and strips out the results so that it's just the first 4 digits (rather than the first 4 digits + '-.....'). Which function would allow me to do this in management studio?

Will Leonard

James K
Flowing Fount of Yak Knowledge

3593 Posts

Posted - 09/10/2013 :  16:51:12  Show Profile  Reply with Quote
If you just want the first four digits, LEFT(YourExtendedZipCode,4) would do it.

But, aren't US zip codes 5 digits? Or, are you thinking about the four-digit portion of the 5+4-digit extended zipcode?
Go to Top of Page

wleonard
Starting Member

USA
30 Posts

Posted - 09/13/2013 :  12:56:32  Show Profile  Reply with Quote
quote:
Originally posted by James K

If you just want the first four digits, LEFT(YourExtendedZipCode,4) would do it.

But, aren't US zip codes 5 digits? Or, are you thinking about the four-digit portion of the 5+4-digit extended zipcode?



Yah yah first 5 was what I meant. Thanks though I'll give this a try.

Will Leonard
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/15/2013 :  04:07:39  Show Profile  Reply with Quote
it should be either

LEFT(Field,5)

or if you're sure that there will be a - always separating zip code you can use this

LEFT(field,CHARINDEX('-',field+ '-')-1)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000