Solved

What function to use to left pad a number with 0's

Posted on 2008-06-18
4
2,081 Views
Last Modified: 2008-09-17
I have a total count being retrieved into a variable in a stored procedure.
Example the value of the variable is an INTEGER datatype with value as 99.... I need to change the value as a char and use it as 000099 and create a string with tis number and more numbers.

99 should be changed to 000099 in characters.
0
Comment
Question by:boppanak
4 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 250 total points
ID: 21817282
you can use

select right(digitis(your_column_name),6)
0
 
LVL 18

Assisted Solution

by:daveslash
daveslash earned 250 total points
ID: 21817401

Momi's solution is BY FAR the easiest. Use it.

If you want something a little more flexible, you could use the to pad with any character:

select right(repeat('*', 6) || yourColumn,6)
... or ...
select right(repeat('0', 6) || yourColumn,6)

HTH,
DaveSlash
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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