SQL Server - 用文本替换货币号码

时间:2014-03-26 17:25:33

标签: sql-server

我需要用文字替换钱号。例如,如果它是66.35,它将显示为66美元和35美分。

这是我要展示的内容,但我不知道如何用$ dollar替换小数。

SELECT Freight, CAST(Freight AS varchar) + ' cents' AS Expr1
FROM dbo.Orders

http://i.imgur.com/8Oe9omn.png

1 个答案:

答案 0 :(得分:0)

你可以在十进制之前和之后分开部分,将每个部分转换为varchar,然后在文本中添加,如下所示:

SELECT Freight, 
cast(cast(floor(Freight) as decimal(2,0)) as varchar) + ' dollars and ' + cast(cast(100*(Freight - floor(Freight)) as decimal (2,0))as varchar) + ' cents'
FROM dbo.Orders