我想在选择
期间将其中一个字段更改为货币类型SELECT AdvertID,NumWords,WeeksRunning,0.5*NumWords*WeeksRunning AS [Cost]
FROM AdvertsTb
如您所见,新字段的格式不会是$ XX.00。那么我必须使用哪个运算符来更改类型以使其显示为货币?
答案 0 :(得分:2)
只需将cost
转换为varchar
并添加$
符号即可。
SELECT AdvertID,NumWords,WeeksRunning,
"$" & CStr(0.5*NumWords*WeeksRunning) AS [Cost]
FROM AdvertsTb
答案 1 :(得分:1)
你需要施展它
SELECT AdvertID,NumWords,WeeksRunning,cast(0.5*NumWords*WeeksRunning as money) AS [Cost]
FROM AdvertsTb
答案 2 :(得分:0)
您还可以尝试CONVERT
方法:
SELECT
AdvertID,
NumWords,
WeeksRunning,
CONVERT(MONEY,0.5*NumWords*WeeksRunning) AS [Cost]
FROM AdvertsTb