有人能引导我朝着正确的方向前进吗?我尝试过尽可能地编辑语法,并搜索了2个小时如何使其工作。但我不能让我的CAST功能正常工作。我做错了什么?
SELECT dbo_orders.ordernumber,
dbo_orders.orderdate,
Sum([dbo_Order Details].priceperunit) AS sumofpriceperunit,
dbo_orders.producttotal,
Sum([dbo_Order Details].costperunit) AS sumofcostperunit,
dbo_orders.shippingtotal,
dbo_tracking.cost,
[dbo_Order Details].dropship,
dbo_orders.cartid
CAST ([dbo_Tracking].cost) AS number
FROM dbo_tracking
INNER JOIN ([dbo_Order Details]
INNER JOIN dbo_orders
ON [dbo_Order Details].ordernumber = dbo_orders.ordernumber)
ON dbo_tracking.numerickey = [dbo_Order Details].ordernumber
GROUP BY dbo_orders.ordernumber,
dbo_orders.orderdate,
dbo_orders.producttotal,
dbo_orders.shippingtotal,
dbo_tracking.cost,
[dbo_Order Details].dropship,
dbo_orders.cartid
HAVING (((
dbo_orders.orderdate)>=(#6/1/2016#)
AND (
dbo_orders.orderdate)<=(#6/30/2016#)));
答案 0 :(得分:2)
msaccess强制转换功能
Cint -- cast to integer
Clng -- long
Cdbl -- double
Csng - single
Cstr - string
Cbool - boolean
SELECT clng(fieldName) FROM tableName
https://www.techonthenet.com/access/functions/datatype/cint.php
添加',',强制转换字段,删除having子句并添加where子句。你可能想要相应地格式化日期。
SELECT dbo_orders.ordernumber,
dbo_orders.orderdate,
Sum([dbo_Order Details].priceperunit) AS sumofpriceperunit,
dbo_orders.producttotal,
Sum([dbo_Order Details].costperunit) AS sumofcostperunit,
dbo_orders.shippingtotal,
dbo_tracking.cost,
[dbo_Order Details].dropship,
dbo_orders.cartid , 'added a comma
CInt ([dbo_Tracking].cost) AS number 'cast accordingly
FROM dbo_tracking
INNER JOIN ([dbo_Order Details]
INNER JOIN dbo_orders
ON [dbo_Order Details].ordernumber = dbo_orders.ordernumber)
ON dbo_tracking.numerickey = [dbo_Order Details].ordernumber
where 'added where clause
dbo_orders.orderdate>= (#6/1/2016#)
AND dbo_orders.orderdate <=(#6/30/2016#)
GROUP BY dbo_orders.ordernumber,
dbo_orders.orderdate,
dbo_orders.producttotal,
dbo_orders.shippingtotal,
dbo_tracking.cost,
[dbo_Order Details].dropship,
dbo_orders.cartid
'removed having clause
答案 1 :(得分:0)
通常,在MS Access中,您可以使用其中一种类型转换函数:
Cdec([dbo_Tracking].cost) AS number
如果您不想要小数,请检查documentation中您想要的类型。
BTW,强制转换的正确语法包括一个类型。例如:
cast([dbo_Tracking].cost as decimal(20, 4))
答案 2 :(得分:0)
您在dbo_orders.cartid