Solved

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

Posted on 2008-06-18
4
2,080 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I tweak this SQL to perform DB2 update rather than listing 17 304
iseries sql set statement failing 2 254
CATALOG A DB2 TCPIP NODE with AN ALIAS 2 122
Monitor SQL Insert 8 45
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 hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

16 Experts available now in Live!

Get 1:1 Help Now