Convert currency to varchar (thousands separator without decimals)

Im trying to convert one of the lines in my select statement, this code works but I'm trying to format it in a different way. Can anyone help?


CONVERT(varchar(20), acct.Min_Amt)  + ' to ' + CONVERT(varchar(20), acct.Max_Amt) AS Cash_Range  ---> The output is  " $234,992.00 to $532,248.00 "

I want the output to be displayed as "$234,992 to $532,249"  <-- without decimals just whole numbers separated by commas.

Thanks !!!
tek07Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
Hi tek07,

CONVERT(varchar(20), ROUND(acct.Min_Amt, 0))  + ' to ' + CONVERT(varchar(20), ROUND(acct.Max_Amt, 0)) AS Cash_Range

Regards,

Patrick
0
tek07Author Commented:
it's not working
0
tek07Author Commented:
it still gives me the output with .00 at the end .
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Scott PletcherSenior DBACommented:
SELECT '$' + REPLACE(CONVERT(VARCHAR(20), CAST(ROUND(acct.Min_Amt, 0) AS MONEY), 1), '.00', '') + ' to $' + REPLACE(CONVERT(VARCHAR(20), CAST(ROUND(acct.Max_Amt, 0) AS MONEY), 1), '.00', '') AS [Cash_Range]


For example:

declare @amt decimal(9, 2)
declare @amt2 decimal(9, 2)
set @amt = 234992.45
set @amt2 = 532248.79

SELECT '$' + REPLACE(CONVERT(VARCHAR(20), CAST(ROUND(@Amt, 0) AS MONEY), 1), '.00', '') +' to $' + REPLACE(CONVERT(VARCHAR(20), CAST(ROUND(@Amt2, 0) AS MONEY), 1), '.00', '')


[That was much harder than you think it should be!]
0
MikeWalshCommented:
SELECT
CONVERT(varchar(20),(CAST (ROUND(4.25,0) as int))) +
' to ' + CONVERT(varchar(20),(CAST (ROUND(25.51,0) AS INT))) AS Cash_Range
0
MikeWalshCommented:
sorry, just change the 4.25 to the min and 25.51 to the max, I was testing... And you will need to add your dollar signs through concatenation.
0
MikeWalshCommented:
Nevermind me.. I didn't fully read. Most be a symptom of the time and the fact that I am still working on a project. I won't give you the commas with my method.. I also see that Scott answered as I was typing my two posts, his looks like what you are after.
0
Aneesh RetnakaranDatabase AdministratorCommented:
If you wanna remove '.00' you can use this

CONVERT(varchar(20), acct.Min_Amt)  + ' to ' + REPLACE(CONVERT(varchar(20), acct.Max_Amt) AS Cash_Range,'.00','')

0
Scott PletcherSenior DBACommented:
Btw, if you prefer, you can use FLOOR() or CEILING() in place of ROUND(), depending on exactly what you want to see for non-zero cents amount.
0
Aneesh RetnakaranDatabase AdministratorCommented:
SELECT CONVERT(varchar(20), '$234,992.00')  + ' to ' + LEFT(CONVERT(varchar(20), '$234,992.00'),CHARINDEX('.','$234,992.00')-1) AS Cash_Range  
0
tek07Author Commented:
im so confused, lol. This si the statement.

SELECT
 
 '$' + CONVERT(varchar(20), ROUND(b.Min_Amt, 0))  + ' to ' + '$' + CONVERT(varchar(20), ROUND(b.Max_Amt, 0)) AS Range_amt

from
bank b

the output is  " $100000.00 to  $200000.00 "   and I need it to have no commas and no decimals so it'll look like this "$100,000 to $200,000".

I dont want to create variables or anything just a simple convert statement.


Appreciate everyone's input. Thanks
0
Scott PletcherSenior DBACommented:
I think my version gave what you req'd in the original q:

SELECT '$' + REPLACE(CONVERT(VARCHAR(20), CAST(ROUND(acct.Min_Amt, 0) AS MONEY), 1), '.00', '') + ' to $' + REPLACE(CONVERT(VARCHAR(20), CAST(ROUND(acct.Max_Amt, 0) AS MONEY), 1), '.00', '') AS [Cash_Range]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MikeWalshCommented:
I would go with Scott's the variables were just for illustration. His makes the most sense and definitely works. Aneeshatingal's first one took some of what scott already supplued anyway. Personally I would use what scott put in the first part of his answer should do you fine.
0
tek07Author Commented:
thanks it works! can u explain the whole statement scottpletcher? whats with the replace and AS Money? then covert and cast at the same time?
0
Scott PletcherSenior DBACommented:
Sorry for the delay, I worked all week-end on SQL recoveries so was out yesterday.

The CAST(... AS MONEY) is so that SQL will "understand" that the third parameter tells it to insert commas; if the datatype isn't MONEY, SQL doesn't recognize the third parameter correctly.

However, the only format that includes comma *also* includes decimal places.  The REPLACE() gets rid of them, by forcing the cents amount to 00, and then replacing the cents in the amount, ".00", with an empty string, "", thus getting rid of the cents.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.