Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format Currency into millions of dollars SQL Server

Tags:

sql

sql-server

Can anyone help me format my dollars data into millions of dollars for SQL Server?

3,000,000

--> $3M

I have this but it's not working

SELECT     '$' + SUM(Sales_Information.Sales_in_Dollars / 1000000) 
                      AS [Sales in Millions]

Doing this gives me #Error

format(SUM(Sales_Information.Sales_in_Dollars / 1000000)
like image 348
user25976 Avatar asked Dec 05 '22 22:12

user25976


2 Answers

The FORMAT function has a way of trimming the thousands

each comma reduces the displayed value by 1000

e.g.

select format(3000000,'$0,,,.000B')
select format(3000000,'$0,,M')
select format(3000000,'$0,K')

(note that I had to use decimals to show 3 million in Billions)

Output:

$0.003B
$3M
$3000K

like image 72
SeanC Avatar answered Dec 19 '22 15:12

SeanC


Try this....

SELECT '$' + CONVERT(VARCHAR(100),CAST(3000000 AS MONEY),1)

RESULT:  $3,000,000.00
like image 20
M.Ali Avatar answered Dec 19 '22 14:12

M.Ali