[英]Why does this SQL code not work in Microsoft Access but works in SQL Server Management Studio?
This code will not work in Microsoft Access but it works in Microsoft SQL Server Management Studio. 此代码在Microsoft Access中将不起作用,但在Microsoft SQL Server Management Studio中将起作用。 What can I do to make this work in Access? 我该怎么做才能在Access中工作? I keep getting a 我不断得到
"Syntax error (missing operator) in query expression 'CAST(od.UnitPrice * od.Quantity * (1 + od.Discount) as decimal(10,2)) 'Order Total'. “查询表达式'CAST(od.UnitPrice * od.Quantity *(1 + od.Discount)为十进制(10,2))'Order Total'的语法错误(缺少运算符)。
Select TOP 5
c.CompanyName as 'Company Name',
CAST(od.UnitPrice * od.Quantity * (1 + od.Discount) as decimal(10, 2)) 'Order Total'
From
Customers as c
Join
Orders as o On c.CustomerID = o.CustomerID
Join
OrderDetails as od On o.OrderID = od.OrderID
Where
od.UnitPrice * od.Quantity * (1 + od.Discount) > 5000
AND c.Country IN ('Austria', 'Denmark', 'Germany', 'Ireland', 'Sweden')
Order By
o.OrderDate desc
you cant use CAST in Access... try with this options: 您不能在Access中使用CAST ...尝试使用以下选项:
Cint -- cast to integer Cint-转换为整数
Clng -- long ng-长
Cdbl -- double CDBL-双
Csng - single CSNG-单
Cstr - string CSTR-字符串
Cbool - boolean Cbool-布尔值
CDec - Decimal CDec-小数
Example: SELECT clng(fieldName) FROM tableName
示例: SELECT clng(fieldName) FROM tableName
In your case: 在您的情况下:
Select TOP 5
c.CompanyName as 'Company Name',
CDec(od.UnitPrice * od.Quantity * (1 + od.Discount)) 'Order Total'
From
Customers as c
Join
Orders as o On c.CustomerID = o.CustomerID
Join
OrderDetails as od On o.OrderID = od.OrderID
Where
od.UnitPrice * od.Quantity * (1 + od.Discount) > 5000
AND c.Country IN ('Austria', 'Denmark', 'Germany', 'Ireland', 'Sweden')
Order By
o.OrderDate desc
Hope this help! 希望有帮助!
I don't think the CAST works OK in Access (if it exists). 我认为CAST在Access(如果存在)中不能正常工作。 I would take the CAST out and change it for something like the CDec() function. 我会取出CAST并将其更改为类似CDec()函数的内容。 You have to use one of the followings in general: https://support.office.com/en-ie/article/Type-Conversion-Functions-8ebb0e94-2d43-4975-bb13-87ac8d1a2202 您通常必须使用以下之一: https : //support.office.com/zh-cn/article/Type-Conversion-Functions-8ebb0e94-2d43-4975-bb13-87ac8d1a2202
The CAST and CONVERT column functions do not seem to work in MS Access. CAST和CONVERT列函数似乎在MS Access中不起作用。
Try the CInt or the CLng function, depending upon whether you want an integer (16 bit) or a long integer (32 bit). 尝试使用CInt或CLng函数,具体取决于您要的是整数(16位)还是长整数(32位)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.