We help IT Professionals succeed at work.

How to Padd zero's on the left side of the column

Last Modified: 2012-08-14

I have the following table
autokey   branch_number
1             24        
2            056      
3              23        
4              2        
5              566      
6              666      
7              1        
8              22        

As you can see the branch_number column contains 2 digits,1 digit and 3 digitis numbers. I need to pad the two and one digit values with zero padded to the left so that all the values in branch_number column are 3 digits.

Can somebody please help me on this?


Watch Question

TimCotteeHead of Software Services

Select Autokey, Right('000' + Cast(Branch_Number As Varchar(3)),3) As Branch_Number from MyTable

Should do it.


Did not work mate
TimCotteeHead of Software Services

So what did you get?


same values as they are in the table(column branch_number)

I need the branch_number column to look as below:

autokey   branch_number
1              024        
2              056      
3              023        
4              002        
5              566      
6              666      
7              001        
8              022    

hope this helps.

Head of Software Services
Unlock this solution and get a sample of our free trial.
(No credit card required)


the datatype is nvarchar. it does not have preceeding spaces it just have 2 digit and 1 digits number and also 3 digits. I want to make it 3 digits so that its uniform.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.