Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 705937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:06:37+00:00 2026-05-14T04:06:37+00:00

Scenario: I have a table1(col1 char(5)); A value in table1 may ‘001’ or ’01’

  • 0

Scenario:

I have a table1(col1 char(5)); A value in table1 may ‘001’ or ’01’ or ‘1’.

Requirement:

Whatever value in col1, I need to retrive it in 5 char length concatenate with leading ‘0’ to make it 5 char long.

Technique I applied:

select right(('00000' + col1),5) from table1; 

I didn’t see any reason, why it doesn’t work? but it didn’t.
Can anyone help me, how I can achieve the desired result?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:06:37+00:00Added an answer on May 14, 2026 at 4:06 am

    Since you’re using a fixed width column, it’s already of size 5 (with whitespace). You need to trim it:

    DECLARE @table1 TABLE (col1 char(5))
    
    INSERT INTO @table1 (col1) VALUES ('12345')
    INSERT INTO @table1 (col1) VALUES ('1')
    
    SELECT RIGHT('00000'+RTRIM(col1),5) FROM @table1
    
    -- Output:
    -- 12345
    -- 00001
    

    Or use varchar instead:

    DECLARE @table2 TABLE (col1 varchar(5))
    
    INSERT INTO @table2 (col1) VALUES ('12345')
    INSERT INTO @table2 (col1) VALUES ('1')
    
    SELECT RIGHT('00000'+col1,5) FROM @table2
    
    -- Output:
    -- 12345
    -- 00001
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SCENARIO: I have two tables, table1(col1 date) and table2(col2 varchar(20)). REQUIREMENT: Whenever anyone updated
We have the following scenario where foo has been renamed as foo1 . foo.col1
I have a scenario like this: There are two tables table1 and table2 .
I have two tables Table1: ColumnA (varchar) Table2: ColumnB (varchar) I need to get
I have a scenario where I need to convert rows to columns. I likely
I have this Mysql scenario table1 -------------- id `7` `8` -------------- 1 10 20
Here is my scenario: I have table A, that has 4 rows (id, col1,
Consider the following MySQL scenario: Table1: id, date, value Table2: id, month, count Table
Here's the scenario: I have 2 tables with data, one is the 2009 version
Here's the scenario: I have 2 tables: CREATE TABLE dbo.API_User ( id int NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.