简体   繁体   English

为什么此SQL代码在Microsoft Access中不起作用,但在SQL Server Management Studio中起作用?

[英]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.

相关问题 为什么在SQL Server 2005 Management Studio中可用的更新查询不能在Java中用作预准备查询? - Why does my update query that works in SQL Server 2005 Management Studio not work as a Prepared Query in Java? 为什么此命令在SQL Server Management Studio中起作用但在PowerShell中不起作用 - Why does this command work in SQL Server Management Studio but not from PowerShell 为什么在MS Access中有效的SQL查询在SQL Server中不起作用? - Why does this SQL query that works in MS Access not work in SQL Server? SQL 查询包含 / isabout 在 SQL Server Management Studio 中完美运行,但它不在代码后面 - SQL query with contains / isabout works perfect in SQL Server Management Studio, but it does not in code behind 西里尔字母不适用于 Microsoft SQL Server Management Studio - Cyrillic alphabet doesnt work with Microsoft SQL Server Management Studio 为什么Microsoft SQL Server 2012查询需要几分钟而不是JDBC 4.0,而在Management Studio中需要几分钟? - Why does Microsoft SQL Server 2012 query take minutes over JDBC 4.0 but second(s) in Management Studio? 为什么 SQL Merge (Upsert) 的相同代码在 Microsoft SQL 服务器控制台中有效,但在 Python 中无效? - Why does identical code for SQL Merge (Upsert) work in Microsoft SQL Server console but doesn't work in Python? Microsoft SQL Server Management Studio 错误 - Microsoft SQL Server Management Studio Error 在Microsoft SQL Server Management Studio中使用正则表达式 - using regex in microsoft sql server management studio Microsoft SQL Server Management Studio中CTE的语法 - Syntax for CTE in Microsoft SQL Server Management Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM