• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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.
0
ram27
Asked:
ram27
1 Solution
 
Aneesh RetnakaranDatabase AdministratorCommented:
select RIGHT('00000'+ cast(urDatabaseField as varchar) , 5 )
0
 
chapmandewCommented:
select replicate('0', 5-len(ltrim(rtrim(fieldname)))) + fieldname
from yourtablename
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

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