如何更改字段的数据类型

时间:2015-02-01 10:48:04

标签: sql ms-access

我想在选择

期间将其中一个字段更改为货币类型
SELECT AdvertID,NumWords,WeeksRunning,0.5*NumWords*WeeksRunning AS [Cost]
FROM AdvertsTb

如您所见,新字段的格式不会是$ XX.00。那么我必须使用哪个运算符来更改类型以使其显示为货币?

3 个答案:

答案 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