0

Can anyone guide me in the right direction with this? I've tried editing my syntax every way possible and searched for 2 hours how to make this work. But I cannot get my CAST function to work properly. What am I doing wrong?

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

3 Answers 3

2

msaccess cast functions

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

added ',' , cast the field, remove having clause and added where clause. you might want to format the date accordingly.

    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
Sign up to request clarification or add additional context in comments.

Comments

0

Normally, in MS Access you use one of the type conversion functions:

Cdec([dbo_Tracking].cost) AS number 

If you don't want a decimal, check the documentation for the type you do want.

BTW, the correct syntax for cast includes a type. For example:

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

2 Comments

Thanks for your help. For some reason it's still giving me Syntax Error (missing operator).
remove having and chuck a where clause before group by and count your parenthesis
0

You are missing a comma next to dbo_orders.cartid

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.