[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Get exact number of chars from storedproc

Posted on 2008-06-26
2
Medium Priority
?
229 Views
Last Modified: 2010-03-19
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
Comment
Question by:ram27
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 750 total points
ID: 21878389
select RIGHT('00000'+ cast(urDatabaseField as varchar) , 5 )
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21878404
select replicate('0', 5-len(ltrim(rtrim(fieldname)))) + fieldname
from yourtablename
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question