In my table, there is a column called zipcode whose datatype is int. And when I am storing a zipcode which starts with 0 (for eg. 08872), it is getting stored as 8872.
Can anybody explain me why is it happening?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
An
INTvalue is numeric – and numerically,08872and8872are identical – both represent the value8872.SQL Server will not store leading zeroes for numerical values. That’s just the way it is.
Either store this as
CHAR(5)instead, or handle the formatting (adding leading zeroes to your zip codes) on the frontend when you need to display it.