Solved

sql right padding zeros after decimal

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 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

14 Experts available now in Live!

Get 1:1 Help Now