用CAST替换MS Access

时间:2017-05-14 03:05:14

标签: sql ms-access

我正在尝试报告我的查询,但Access中不允许“CAST”。我按照指示更新了我的括号,但仍然在JOIN操作中出现'语法错误。'有关如何正确设置括号的任何建议吗?

select v.VendorID, v.Name,
CCur(Format(sum(p.ListPrice * (1 - sp.DiscountPercent) * od.OrderQuantity), "0.00")) as Sales,
sum(p.ListPrice-p.Cost) as Profit,
sum(od.OrderQuantity) as Quantitiy, sum(sp.DiscountPercent) as Discounts
from ((((vendor v
join product p
on v.VendorID = p.VendorID)
join OrderDetail od
on p.ProductID = od.ProductID)
join OrderHeader oh
on od.OrderID = oh.OrderID)
join SalesPromotion sp
on od.SalesPromotionID = sp.SalesPromotionID)
where year(oh.OrderDate) = 2014
Group by v.VendorID, v.Name
order by Sales DESC

谢谢!

2 个答案:

答案 0 :(得分:1)

这里四舍五入到小数点后两位。

在处理金额时,您应该转换为货币,因此:

CCur(Format(sum(p.ListPrice * (1 - sp.DiscountPercent) * od.OrderQuantity), "0.00")) as Sales,

答案 1 :(得分:0)

您可以使用MS-Access中的类型转换功能。

https://support.office.com/en-ie/article/Type-Conversion-Functions-8ebb0e94-2d43-4975-bb13-87ac8d1a2202

也许CDbl会在这种情况下帮助你。