Link to home
Start Free TrialLog in
Avatar of matrix_aash
matrix_aashFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Hi,

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?

Thanks,

Aash.
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

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

Should do it.
Avatar of matrix_aash

ASKER

Did not work mate
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.

Aash.
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.