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

Leading zeros 2

Status
Not open for further replies.

boatguy

Programmer
Oct 22, 2001
153
0
0
US
I am trying to insert records from a csv file and one of the fields is zipcode. The issue I am having is that zip codes that start with a leading zero, end up inserting with the zero removed. How can I maintain the zero?
 
yeah, the only time you should be using numeric datatypes is when you want to perform numeric operations on them

when was the last time you wanted to know the sum of all zipcodes?

:)

r937.com | rudy.ca
 
yes, zip codes are best stored as strings since mathematical operations won't be used on the data...plus having it as a string will support non US postal codes that contain letters.

Depending on your usage, since zip codes are always 5 characters long, its sometimes better to use char(5) instead of varchar (or int for that matter) to save a little memory. (a byte or two saved per record may not seem alot, till you have 1 million records)

If you also have zip suffixes it is sometimes best to seperate them into a seperate column, but depending on your setup is not always the best option.
 
I would make it larger than 5 chars long in the DB if your intending to have people input info outside the US. In canada the postal code is 6 chars long, well, actually 7 cause their is a space between the first 3 chars and the last 3 chars
 
One of our databases has postal codes for seven countries. I also keep a column for country code and base my output mask on the country code using a small table that has CountryCode and PostalCodeMask.

Lyndon
 
thats a fantastic idea,,, kicking myself right now...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top