Results 1 to 5 of 5
  1. #1
    markpastoril is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2018
    Posts
    62

    want to ask if this code would run?

    want to ask if this would run in sql server?i've put this code in a query.

    so this is the code:

    SELECT VehicleMiles.CarNum, VehicleMiles.DorDate, VehicleMiles.SpeedoEnd, (SELECT SpeedoEnd FROM VehicleMiles AS Alias WHERE DorDate = (SELECT Max(DorDate) FROM VehicleMiles AS Alias2 WHERE Alias2.DorDate < VehicleMiles.DorDate AND Alias2.CarNum = VehicleMiles.CarNum) AND Alias.CarNum = VehicleMiles.CarNum) AS PrevEnd, [SpeedoEnd]-[PrevEnd] AS MilesDriven


    FROM VehicleMiles
    ORDER BY VehicleMiles.CarNum, VehicleMiles.DorDate, VehicleMiles.SpeedoEnd;

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    So what happens? Does it run in Access?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    markpastoril is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Aug 2018
    Posts
    62
    yeah, it runs in access, but it won't take effect when I use the sql server database. I wonder how to write it in sql code for me to use it?

  4. #4
    Minty is offline VIP
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    What does "won't take effect" mean?

    As far as I can tell there is nothing in that SQL statement that SQL Server wouldn't understand.
    If you open a new query window in SMSS and run it what error do you get or does it return some results ?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I don't see anything that would stop it from running in SQL Server either, but it is unnecessarily complex with the 2 subqueries. Try this:

    http://allenbrowne.com/subquery-01.html#AnotherRecord
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 5
    Last Post: 08-29-2016, 04:33 AM
  2. Replies: 20
    Last Post: 10-13-2015, 09:05 AM
  3. Replies: 3
    Last Post: 10-16-2014, 08:49 AM
  4. Replies: 7
    Last Post: 05-28-2013, 09:11 AM
  5. Replies: 1
    Last Post: 05-04-2013, 12:19 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