user3329770
user3329770

Reputation: 11

I am converting char zip code to INT in SQL and I need to preserve the leading zero if there is one

Using SQL, how do I convert a 5 digit zip code in integer format to a character format and still preserve the leading zero if there is one?

Upvotes: 0

Views: 302

Answers (1)

Greg
Greg

Reputation: 3522

If you store a number as a number in SQL, it will always remove the leading zero. You are telling SQL that it's a number, and a number doesn't need leading zeros.

2 options are to:

1) Save it as a string and convert it to a number in your application

2) Save it as a number and format it with leading 0's in your application

Upvotes: 3

Related Questions