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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Zip Code Field needs to be an Integer BUT what about leading ZEROES?

Status
Not open for further replies.

nkomokov

Technical User
Nov 9, 2005
14
US
I have a ZipCode field that needs to be an integer for query purposes, but it lops off the leading zeroes on zips like 03421. Is there a way to make it allow leading zeroes other than changing the datatype to char?
 
Leave it as an integer.

The leading zero is ONLY important when people are looking at it, so add the zero's when selecting this data.

Ex.

Select Right('00000' + Convert(VarChar(10), ZipCode), 5)
From Table



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Soooooo... when doing a search by ZipCode, I would instruct users to not type in the leading zeroes?
 
Hehe... good point.

Make it char(5) or something but with additional CHECK constraint.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
After second thought... leave it as an integer. Even if user types 00523, this is interpreted as 523 by default.

This of course assumes leading zeros have no other purposes than being a "filler".

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top