Reputation: 7
This code will not work in Microsoft Access but it works in Microsoft SQL Server Management Studio. What can I do to make this work in 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'.
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
Upvotes: 0
Views: 304
Reputation: 20302
The CAST and CONVERT column functions do not seem to work in MS Access.
Try the CInt or the CLng function, depending upon whether you want an integer (16 bit) or a long integer (32 bit).
Upvotes: 0
Reputation: 745
you cant use CAST in Access... try with this options:
Cint -- cast to integer
Clng -- long
Cdbl -- double
Csng - single
Cstr - string
Cbool - boolean
CDec - Decimal
Example: 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!
Upvotes: 1
Reputation: 347
I don't think the CAST works OK in Access (if it exists). I would take the CAST out and change it for something like the CDec() function. 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
Upvotes: 1