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
 char format of zip code

Author  Topic 

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2015-04-14 : 09:08:11
Hello -

I have a character string for a zip code field. I am only looking for zip codes in the 01001 - 02791 range. Will where zip_code between '01001' and '02791' work on a character field? It seems to be dropping out some records but I cant find them.....

Thanks!

MichaelJSQL
Constraint Violating Yak Guru

252 Posts

Posted - 2015-04-14 : 09:23:18
It should unless they were stored with a leading zero dropped.

CREATE TABLE #Zips
( ID int IDENTITY(1,1),
ZIPCode Char(5)
)

INSERT INTO #Zips
VALUES('01001'),('02791'),('02792'),('02051'),('02027'),('01000'),('01309')

SELECT * FROM #Zips
WHERE ZIPCode BETWEEN '01001' AND '02791'
Go to Top of Page

jcb267
Constraint Violating Yak Guru

291 Posts

Posted - 2015-04-14 : 09:29:09
I just discovered that some had the leading zero dropped....
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2015-04-14 : 20:41:57
Common issue when data is put into Excel for "handling purposes" . Excel chops off leading zeros (unless you carefully format the data as TEXT during import). We had a client who decided to use leading zeros on Product Codes ... turned out to be a bad choice as they were Excel fanatics (well ... not fanatical enough, as it turned out!)
Go to Top of Page
   

- Advertisement -