2017-04-12 65 views
0

任何人都可以引導我在正確的方向嗎?我試過儘可能地編輯我的語法,並搜索了2個小時如何完成這項工作。但我無法讓我的CAST功能正常工作。我究竟做錯了什麼?SQL 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

通常情況下,在MS Access使用的類型轉換功能之一:

Cdec([dbo_Tracking].cost) AS number 

如果你不想要一個小數,檢查documentation爲你想要的類型。

順便說一下,鑄造的正確語法包括一個類型。例如:

cast([dbo_Tracking].cost as decimal(20, 4)) 
+0

感謝您的幫助。由於某些原因,它仍然給我語法錯誤(缺少運算符)。 – DRK

+0

刪除有並且在一組之前查找一個where子句並且統計你的括號 – maSTAShuFu

0

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

加入 '',鑄領域中,除去具有條款和加入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 
0

你缺少一個逗號旁邊dbo_orders.cartid