Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 357
  • Last Modified:

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.
0
matrix_aash
Asked:
matrix_aash
  • 3
  • 3
1 Solution
 
TimCotteeCommented:
Select Autokey, Right('000' + Cast(Branch_Number As Varchar(3)),3) As Branch_Number from MyTable

Should do it.
0
 
matrix_aashAuthor Commented:
Did not work mate
0
 
TimCotteeCommented:
So what did you get?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
matrix_aashAuthor Commented:
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.
0
 
TimCotteeCommented:
What is the datatype for the Branch_Number field? Does it currently have records with preceeding spaces?

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

May solve the problem.
0
 
matrix_aashAuthor Commented:
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.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now