Results 1 to 11 of 11
  1. #1
    daniel.ru92 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    20

    Cross-Midnight Shift Problem

    Query is supposed to pull all the records from that shift. Each work shift begins at 8 am and ends at 8 the next morning. At any time during the shift in which the query runs, it pull all the records from that day and if the current time after midnight, the records yesterday.


    After I enabled query design error:
    "The SQL statement could not be executed because it contains ambiguous outer joins. To force one of the joins to be performed first, create a separate query that performs the first join and then include that query in your SQL statement."

    Here is the SQL of query:
    SELECT Deliveries.ReceptionTime, Customers.FullName, [StreetName] & " " & [Deliveries.ApartNumber] & " / " & [Deliveries.HouseNumber] & [Deliveries.EntryNumber] & ", " & IIf([Deliveries.IsUnit]=True,"unit, ","") & [CityName] AS Address, Deliveries.PayByCreditCard, Deliveries.IsPrepaid, Deliveries.TotalPrice, Deliveries.Comments
    FROM Cities LEFT JOIN ((Customers LEFT JOIN Deliveries ON Customers.[CustomerID] = Deliveries.[CustomerID]) INNER JOIN Streets ON Deliveries.StreetID = Streets.StreetID) ON Cities.CityID = Streets.CityID
    WHERE (((Deliveries.ReceptionTime)="Date()") AND ((DatePart([h],Now()))>8) AND ((DatePart([h],[ReceptionTime]))>8)) OR (((Deliveries.ReceptionTime)="Date()") AND ((DatePart([h],Now()))<8) AND ((DatePart([h],[ReceptionTime]))<8)) OR (((Deliveries.ReceptionTime)=DateAdd("d",-1,Date())) AND ((DatePart([h],Now()))<8) AND ((DatePart([h],[ReceptionTime]))>8));

    Here is Printscreen of the query:



    BIG THANKS GUYS!!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Try changing the INNER join between Streets and Deliveries to outer type (LEFT or RIGHT).
    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
    daniel.ru92 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    20
    Nope...
    "Syntax error in JOIN operation."

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You clicked on the line that represents the link and opened the dialog box to change the join type?
    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.

  5. #5
    daniel.ru92 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    20
    I could not figure out how to do it ... Quite new in SQL...

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Open query in design view. Click on the line that connects the tables. Make choice "Include ALL records from Deliveries..."
    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.

  7. #7
    daniel.ru92 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    20
    I did it and still the same problem ...
    "The SQL statement could not be executed because it contains ambiguous outer joins. To force one of the joins to be performed first, create a separate query that performs the first join and then include that query in your SQL statement."

    SQL Code:
    SELECT Deliveries.ReceptionTime, Customers.FullName, [StreetName] & " " & [Deliveries.ApartNumber] & " / " & [Deliveries.HouseNumber] & [Deliveries.EntryNumber] & ", " & IIf([Deliveries.IsUnit]=True,"unit, ","") & [CityName] AS Address, Deliveries.PayByCreditCard, Deliveries.IsPrepaid, Deliveries.TotalPrice, Deliveries.Comments
    FROM Cities LEFT JOIN ((Customers LEFT JOIN Deliveries ON Customers.[CustomerID] = Deliveries.[CustomerID]) LEFT JOIN Streets ON Deliveries.StreetID = Streets.StreetID) ON Cities.CityID = Streets.CityID
    WHERE (((Deliveries.ReceptionTime)=Date()) AND ((DatePart([h],Now()))>8) AND ((DatePart([h],[ReceptionTime]))>8)) OR (((Deliveries.ReceptionTime)=Date()) AND ((DatePart([h],Now()))<8) AND ((DatePart([h],[ReceptionTime]))<8)) OR (((Deliveries.ReceptionTime)=DateAdd("d",-1,Date())) AND ((DatePart([h],Now()))<8) AND ((DatePart([h],[ReceptionTime]))>8));


  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The arrow direction between Deliveries and Streets looks backwards.

    Did you select "Include ALL records from Deliveries ..."?

    Select and delete the line.

    Click on StreetID in Streets and drag to StreetID in Deliveries.

    Then select the jointype.
    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.

  9. #9
    daniel.ru92 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    20
    I did so, I did the opposite, I did every possible way and it keeps the same error. There could be a problem that I set up two columns in a query with one of them even not up on tables (up on date), and on these columns I run the filter of rows??

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Sorry, I hadn't even looked at the filter criteria. Does the query open if there are no criteria? I really can't see any reason all these tables cannot be joined in query.

    Filter criteria can be applied to calculated fields.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  11. #11
    jwreding is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Feb 2011
    Posts
    34
    Is it just me, or do the joins on Customers/Deliveries and Cities/Streets look like they're going in the wrong direction?

    First, is there a need for an outer join between Customers and Deliveries? Do you ever have any records in Deliveries that don't have a corresponding Customer record? Is your entry form for Deliveries based on a query that only displays Customer records already in the table? If so, then you can change this to an inner join by double clicking the join line and choosing option 1.

    The error message is telling you it doesn't like the outer joins you have, so if you take care of that one then maybe it will cooperate. If not, you may need to look at the Cities/Streets join and either change its direction (which I'd do anyway), or convert it also to an inner join.

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

Similar Threads

  1. Problem with Cross qry
    By fcarboni in forum Access
    Replies: 1
    Last Post: 05-11-2012, 01:51 PM
  2. Calculating time AT midnight
    By atom in forum Queries
    Replies: 11
    Last Post: 02-05-2012, 04:27 PM
  3. cross table problem
    By humanmaycry in forum Queries
    Replies: 3
    Last Post: 07-20-2011, 12:08 PM
  4. Problem with cross tab on column heading
    By pascal_22 in forum Queries
    Replies: 0
    Last Post: 12-01-2010, 08:00 AM
  5. Replies: 8
    Last Post: 05-24-2010, 04:24 AM

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