Results 1 to 7 of 7
  1. #1
    magnusstefan is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Saltsjöbaden, Sweden
    Posts
    52

    Question Is there any documentation about the automatic CAST functions in Access 2010/2013?

    I will try to explain why I ask this by giving an example first:

    Suppose we have a sales order database, and there we have the table "Orders". In the table we have columns like "OrderNumber", "Orderdate" and "Shipdate".
    OK?

    Now we want to know how many days it is between order date and ship date for each order.
    According to SQL Standard, as far as I have learnt it, the following SQL Query is then supposed to work:

    Code:
    SELECT OrderNumber, OrderDate, ShipDate,
    CAST (ShipDate - OrderDate AS INTEGER)
    AS DaysElapsed
    FROM Orders;
    But it does not. Instead I got an error message:
    "Syntax error (operator missing)..."


    After one hours work I did find out this: if I just remove a few things in the second line, and only keep this it works fine:
    Code:
    ShipDate - OrderDate
    So this seems to be the way in Access:



    Code:
    SELECT OrderNumber, OrderDate, ShipDate,
    ShipDate - OrderDate
    AS DaysElapsed
    FROM Orders;

    Now, is there any documentation anywhere that explains how Access works with automatic CAST-conversions?
    Including, syntax, what Access does and does not regarding CAST/conversions when you write SQL queries?
    Does anyone know?

    (When I search for "CAST" or "Conversion" in the internal help system I do not get anything useful.)

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    There is no CAST. Just use the functions and give it a label. AS

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    CAST (and CONVERT) are SQL Server (and perhaps other platforms) functions, not valid in Access. In the case mentioned, CInt() would be an alternative.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    magnusstefan is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Saltsjöbaden, Sweden
    Posts
    52
    OK, Thank you!


    You mean like:
    Code:
    ShipDate - OrderDate AS DayDifference
    and then I am done? Nothing more to worry about, right?

    One more question about this if you please: Since I got the answer as a numeral, not as a date number, i suppose that Access actually convert the dates to numerals which basically is the same as if CAST has been used in another system, only that in the Access World this is not called Casting?

  5. #5
    magnusstefan is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Saltsjöbaden, Sweden
    Posts
    52
    OK, thank you!

    CInt() is VB code, right?
    If you not are skilled in VB, there is no SQL Alternative, or?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by magnusstefan View Post
    OK, thank you!

    CInt() is VB code, right?
    If you not are skilled in VB, there is no SQL Alternative, or?
    No, not VB code and will work in the query.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    magnusstefan is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Oct 2014
    Location
    Saltsjöbaden, Sweden
    Posts
    52
    Quote Originally Posted by pbaldy View Post
    No, not VB code and will work in the query.
    Yes, of course you are right! (Sorry for late answer!)

    That is: I have now read or worked through all examples of SLQ commands in Pindaro Epaminonda Demertzoglou's excellent book "Microsoft Access SQL Comprehensive". So I know for sure now, that you are right! =)
    And I can, without reservation, recommend the book to anyone who need some improvement of their knowledge about SQL-code related to MS Access, or just for repetition or checking up something!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 08-13-2014, 10:32 PM
  2. Replies: 3
    Last Post: 04-02-2014, 02:30 AM
  3. Using Labels in Reports in Access 2013 and 2010
    By MillerRL143 in forum Reports
    Replies: 3
    Last Post: 08-08-2013, 09:12 PM
  4. Replies: 3
    Last Post: 06-19-2013, 04:45 PM
  5. built in functions in access 2010
    By Jean S in forum Access
    Replies: 5
    Last Post: 12-05-2012, 11:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums