SQL Server Concatenate string column value to 5 char long
Posted
by mrp
on Stack Overflow
See other posts from Stack Overflow
or by mrp
Published on 2010-04-04T01:58:05Z
Indexed on
2010/04/04
2:23 UTC
Read the original article
Hit count: 253
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?
© Stack Overflow or respective owner