Solved

sql right padding zeros after decimal

Posted on 2011-03-14
2
1,687 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 142

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

832 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