Solved

Get exact number of chars from storedproc

Posted on 2008-06-26
2
175 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 250 total points
Comment Utility
select RIGHT('00000'+ cast(urDatabaseField as varchar) , 5 )
0
 
LVL 60

Expert Comment

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

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Return rows that match the first row 3 39
get all customers 2 38
How to check data in sql table 11 37
Record open by another user 6 40
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 …
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now