Results 1 to 10 of 10
  1. #1
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53

    Selection Query not working properly

    Hello I have the following query:



    Click image for larger version. 

Name:	Capture.PNG 
Views:	8 
Size:	5.5 KB 
ID:	17572

    SELECT ShipDeliveryDates.Project_Number, Min(ShipDeliveryDates.Sched_Delivery_Date) AS Sched_Next_Delivery_Date, ShipDeliveryDates.Act_Delivery_Date
    FROM ShipDeliveryDates
    GROUP BY ShipDeliveryDates.Project_Number, ShipDeliveryDates.Act_Delivery_Date;

    Using this query I would like to pick out all the projects with their upcoming delivery dates. The query is not working properly, all the delivery dates show up for each project.
    The query works properly if I delete the selection of Act_Delivery_Date, but I need it there.

    Any help would be welcomed.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    They show up because you are grouping on the date field. Instead of GROUP BY under that field maybe use Min.

    Maybe you need criteria under one of the date fields: >=Date()
    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
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Quote Originally Posted by June7 View Post
    They show up because you are grouping on the date field. Instead of GROUP BY under that field maybe use Min.

    Maybe you need criteria under one of the date fields: >=Date()
    In case something hasn't been shipped I don't want to have >=Date().

    If I use Min under that field a date that has an Act_Delivery_Date not corresponding to the Sched_Delivery_Date can show up. The two showing up in this query must always be under the same record in the ShipDeliveryDates table.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    Doesn't this table have only 1 record for each project? If so, grouping is meaningless. Need to refine the filter criteria.

    Do you want all records with an upcoming Sched_Delivery_Date?

    Do you want all records where the Act_Delivery_Date is blank?

    Do you want both criteria?
    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
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Quote Originally Posted by June7 View Post
    Doesn't this table have only 1 record for each project? If so, grouping is meaningless. Need to refine the filter criteria.

    Do you want all records with an upcoming Sched_Delivery_Date?

    Do you want all records where the Act_Delivery_Date is blank?

    Do you want both criteria?
    The ShipDeliveryDates table can have more than 1 record for each project:

    Project_Number Shipment_Number Sched_Ship_Date Sched_Delivery_Date Actual_Ship_Date Actual_Delivery_Date
    1020 1 30/07/2014 02/08/2014
    1020 2 31/07/2014 03/08/2014

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    So what records do you want? The latest Shipment_Number for each Project_Number? There is an example of that in post 24 of your other thread https://www.accessforums.net/program...71/index2.html

    Assuming Shipment_Number is unique, try:

    SELECT * FROM ShipDeliveryDates WHERE Shipment_Number IN (SELECT Max(Shipment_Number) AS SN FROM ShipDeliveryDates GROUP BY Project_Number);
    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
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Ok so I just thought about it. What I want is a query that will give me the upcoming shipment for each project. From the table below it would select:

    1020, 30/07/2014, ""

    Project_Number Shipment_Number Sched_Ship_Date Sched_Delivery_Date Actual_Ship_Date Actual_Delivery_Date
    1020 1 30/07/2014 02/08/2014
    1020 2 31/07/2014 03/08/2014

    However from the table below it would select:

    1020, 31/07/2014, "" ---> It selected the second one because the first one has already been shipped (has actual ship date)

    Project_Number Shipment_Number Sched_Ship_Date Sched_Delivery_Date Actual_Ship_Date Actual_Delivery_Date
    1020 1 30/07/2014 02/08/2014 30/07/2014
    1020 2 31/07/2014 03/08/2014

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,622
    So you want only the first scheduled shipment where Actual_Ship is blank?

    SELECT * FROM ShipDeliveryDates WHERE Shipment_Number IN (SELECT Min(Shipment_Number) AS SN FROM ShipDeliveryDates WHERE Actual_Ship_Date Is Null GROUP BY Project_Number);
    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
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Quote Originally Posted by June7 View Post
    So you want only the first scheduled shipment where Actual_Ship is blank?

    SELECT * FROM ShipDeliveryDates WHERE Shipment_Number IN (SELECT Min(Shipment_Number) AS SN FROM ShipDeliveryDates WHERE Actual_Ship_Date Is Null GROUP BY Project_Number);
    Hmm, this doesn't seem to work properly. If the first one has an actual_ship_date it still picks it up.

  10. #10
    zipaway is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    53
    Oh I figured it out. This is what I should use.

    SELECT ShipDeliveryDates.Project_Number, Min(ShipDeliveryDates.Sched_Shed_Date) AS Sched_Next_Ship_Date
    FROM ShipDeliveryDates
    GROUP BY ShipDeliveryDates.Project_Number, ShipDeliveryDates.Act_Ship_Date
    HAVING (((ShipDeliveryDates.Act_Ship_Date) Is Null));

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

Similar Threads

  1. accde file not working properly
    By joshynaresh in forum Database Design
    Replies: 9
    Last Post: 10-28-2013, 04:42 AM
  2. Checkboxes not working properly
    By TK03 in forum Access
    Replies: 1
    Last Post: 12-24-2012, 09:04 AM
  3. Update Query Not Working Properly !
    By hamxa7 in forum Queries
    Replies: 3
    Last Post: 09-20-2012, 04:58 PM
  4. access program not working properly!
    By accesshelpme in forum Access
    Replies: 1
    Last Post: 05-13-2012, 03:43 PM
  5. Query on chart not working properly!
    By Sim_ in forum Queries
    Replies: 0
    Last Post: 10-28-2009, 09:38 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