Get exact number of chars from storedproc

Hi,

I want to retrieve value from database if the value has lessthan 5 digits i need to append zeros to make 5 charact or digit using storedprocedure in Sql server 2005.
example, if database has value as "12", my stored procudure should return "00012".
Basically i need to do something like padding left with '0'.

Can you please help me on this.



thanks,
Ram.
ram27Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Aneesh RetnakaranConnect With a Mentor Database AdministratorCommented:
select RIGHT('00000'+ cast(urDatabaseField as varchar) , 5 )
0
 
chapmandewCommented:
select replicate('0', 5-len(ltrim(rtrim(fieldname)))) + fieldname
from yourtablename
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.