Solved

Get exact number of chars from storedproc

Posted on 2008-06-26
2
204 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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Degrading on Write 13 72
Query group by data in SQL Server - cursor? 3 64
What is this datetime? 1 25
SSRS 2013 - Finding Datasets/StoredProcedures 4 32
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

713 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