467,149 Members | 1,361 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,149 developers. It's quick & easy.

formatting numbers keeping the lead zero

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
  • viewed: 1297
Share:
1 Reply
ck9663
Expert 2GB
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.

Similar topics

10 posts views Thread by Pascal | last post: by
7 posts views Thread by Christopher Robin | last post: by
4 posts views Thread by John Sutor | last post: by
7 posts views Thread by ilona | last post: by
5 posts views Thread by Bilgehan.Balban@gmail.com | last post: by
2 posts views Thread by jodyblau | last post: by
6 posts views Thread by Tomasz J | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.