By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,766 Members | 1,295 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,766 IT Pros & Developers. It's quick & easy.

formatting numbers keeping the lead zero

P: 1
I need to format interger variable such as 10, 20 into varchar such as 010, 020.
Do you have any suggestions?
Thanks
Sep 29 '08 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
Expand|Select|Wrap|Line Numbers
  1. declare @myIntVar int
  2.  
  3. set @myIntVar = 12
  4.  
  5. select  right('00000' + cast(@myIntVar as varchar(5)),5)
note:

This code is for a 5-digit number. Adjust the code as necessary.

-- CK
Sep 29 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.