left zero and int data type

I have a column in SQL 2005 with data type int I want to insert into this column values like (0000,0001,0002,0003,.....) but SQL trim left zero and insert values like (0,1,2,3,...), can I do that where data type still int not else?
Who is Participating?

Its sql server built in feature of doing this.
To do same you have to either change data type or insert as it is and while showing / retrieving it add zeros.

try this:
select right(replicate('0',4)+ convert(varchar(4),CityID),4) from Cities

Hope this solves your problem.
no you cant do that since your data type is int. You should change it to varchar or use a function that will add the trailing zeros to the number and use that function to get the values as in the format that you deserve...
Anthony PerkinsCommented:
>>can I do that where data type still int not else?<<
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.