将货币格式化为数百万美元的SQL Server

时间:2023-01-14 14:56:06

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

任何人都可以帮我格式化我的美元数据到数百万美元的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

这样做会给我#Error

format(SUM(Sales_Information.Sales_in_Dollars / 1000000)

3 个解决方案

#1


The FORMAT function has a way of trimming the thousands

FORMAT功能有一种修剪成千上万的方法

each comma reduces the displayed value by 1000

每个逗号将显示的值减少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)

(请注意,我必须使用小数来显示数十亿的300万)

Output:

$0.003B
$3M
$3000K

$ 0.003B $ 3M $ 3000K

#2


Try this....

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

RESULT:  $3,000,000.00

#3


just divide your currency with 1000000 and and an 'M' to its end

只需将您的货币除以1000000,并将“M”除以其结尾

#1


The FORMAT function has a way of trimming the thousands

FORMAT功能有一种修剪成千上万的方法

each comma reduces the displayed value by 1000

每个逗号将显示的值减少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)

(请注意,我必须使用小数来显示数十亿的300万)

Output:

$0.003B
$3M
$3000K

$ 0.003B $ 3M $ 3000K

#2


Try this....

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

RESULT:  $3,000,000.00

#3


just divide your currency with 1000000 and and an 'M' to its end

只需将您的货币除以1000000,并将“M”除以其结尾