Solved

sql right padding zeros after decimal

Posted on 2011-03-14
2
1,707 Views
Last Modified: 2012-05-11
Hi, I am trying to add right padding zeros to my decimal values but I get stuck.

So far I can add left padding zeros and remove the dcimal point,
the issue is that when I get a value of 2.43 then I can convert it to 000243 but if its 2.4 then the converision is to 000024. I need to modify the query so I can have such result:
000243
000240
etc..

 
SELECT RIGHT('0000000000' + CONVERT(VARCHAR,REPLACE([CustFinTrxnNetAmt], '.', '')), 10)  FROM [Transactions]

Open in new window


Thank you for your answer.
0
Comment
Question by:rkanabus
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35128753
first, convert to varchar, then remove comma, finally left pad:
SELECT RIGHT('0000000000' + REPLACE( CONVERT(VARCHAR(10), CONVERT(DECIMAL(20,4), [CustFinTrxnNetAmt])) , '.', '') , 10)  FROM [Transactions]

Open in new window

0
 

Author Comment

by:rkanabus
ID: 35128778
Excellent, thank you!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

838 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