SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Format the Amount


Format the Amount

Author
Message
shohelr2003
shohelr2003
Right there with Babe
Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)

Group: General Forum Members
Points: 767 Visits: 610
Dear,
My client requires to add a hyphen(-) in lieu of comma(,) in the field of amount. But client requires only one hyphen(-) in the amount. For example, Total price is 10,000,000 but new requirement is 10-000000.

Say if I execute "select amount from mytable". The result is '10-000000'. Here I need to do some formatting. But I have no idea.

Please help me to sort out the problem.

Rgds,
Akbar
J Livingston SQL
J Livingston SQL
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11979 Visits: 37516
normally formatting is better left to the front end app to perform.
sometimes however this isn't always poss or desired.....

so in this case, how does your client want the following displayed?

-10,000,000
1
10
100
1,000
10,000
100,000
1,000,000

________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day

Igor Micev
Igor Micev
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10200 Visits: 5156
There is always solution for a particular case. But what about cases without any commas?
Here is one proposal:

declare @amt varchar(20)
set @amt = '10,000,000.00'
--desired is 10-000000.00
set @amt = substring(replace(@amt,',','-'),1,charindex('-',replace(@amt,',','-'),1))+substring(replace(@amt,',',''),charindex('-',replace(@amt,',','-'),1),len(replace(@amt,',',''))-(charindex(replace(@amt,',','-'),'-',1)))
print @amt



IgorMi

Igor Micev,
My blog: www.igormicev.com
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (211K reputation)SSC Guru (211K reputation)SSC Guru (211K reputation)SSC Guru (211K reputation)SSC Guru (211K reputation)SSC Guru (211K reputation)SSC Guru (211K reputation)SSC Guru (211K reputation)

Group: General Forum Members
Points: 211405 Visits: 41977
shohelr2003 (5/18/2013)
Dear,
My client requires to add a hyphen(-) in lieu of comma(,) in the field of amount. But client requires only one hyphen(-) in the amount. For example, Total price is 10,000,000 but new requirement is 10-000000.

Say if I execute "select amount from mytable". The result is '10-000000'. Here I need to do some formatting. But I have no idea.

Please help me to sort out the problem.

Rgds,
Akbar


No reflection on you, Akbar.

That's one of the oddest formatting requirements I've ever seen for numeric values. Why on Earth does the client need it that way?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
shohelr2003
shohelr2003
Right there with Babe
Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)Right there with Babe (767 reputation)

Group: General Forum Members
Points: 767 Visits: 610
Thanks, IgorMi. It works.

@Jeff Moden, this is earth, the most interesting place.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search