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

    Need help with an Update Query

    I've been stuck working on this SQL Update query for a while and not getting anywhere; any help would greatly be appreciated.

    I have two tables and they have the following relevant fields:



    Projects
    Project_Number (Primary Key)
    Sched_Next_Ship_Date

    Ship&Delivery Dates
    ID (Primary Key)
    Project_Number
    Component_Number
    Sched_Ship_Date

    Ship&Delivery Dates (Sample Table)
    Click image for larger version. 

Name:	image.png 
Views:	7 
Size:	6.7 KB 
ID:	16577

    A project may have more than one component with different ship dates. The Sched_Next_Ship_Date field should take the upcoming component's Sched_Ship_Date for that project. So for instance project 10135's Sched_Next_Ship_Date would be 27/05/14 since that is the upcoming component out for shipment relative to today's date.

    The SQL query below simply adds the last entered Sched_Ship_Date to the projects table (for above example would add 30/05/2014); this is incorrect. I want the 'upcoming' ship date to be added to the projects table. The 'upcoming' ship date would be the date that is coming up next relative to today's date. I think CURDATE and a WHERE clause need to be added to the end of this query to make it work like I want it to but I don't know how to do it. Let me know if this is possible or not.


    Query so far:

    UPDATE Projects INNER JOIN [Ship&Delivery Dates] ON Projects.Project_Number = [Ship&Delivery Dates].Project_Number SET Projects.Sched_Next_Ship_Date = [Ship&Delivery Dates].[Sched_Ship_Date]

  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
    This appears to be saving duplicate data. The Sched_Next_Ship_Date can be retrieved by query whenever needed. It is not necessary to store in another table. Stored or not, it is the same query to retrieve the value. The extra step of committing the value to another table is unnecessary.

    You want to retrieve the date that is closest to and later than or equal to the current date? The component number is not a consideration? Try:

    SELECT Project_Number, Min(Sched_Ship_Date) AS Sched_Next_Ship_Date FROM ShipDeliveryDates WHERE Sched_Ship_Date>=Date() GROUP BY Project_Number;


    BTW, advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    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
    This appears to be saving duplicate data. The Sched_Next_Ship_Date can be retrieved by query whenever needed. It is not necessary to store in another table. Stored or not, it is the same query to retrieve the value. The extra step of committing the value to another table is unnecessary.

    You want to retrieve the date that is closest to and later than or equal to the current date? The component number is not a consideration? Try:

    SELECT Project_Number, Min(Sched_Ship_Date) AS Sched_Next_Ship_Date FROM ShipDeliveryDates WHERE Sched_Ship_Date>=Date() GROUP BY Project_Number;


    BTW, advise no spaces or special characters/punctuation (underscore is exception) in naming convention.
    Wow this makes a lot of sense, thank you so much!

    And yeah I will change the naming convention.

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

Similar Threads

  1. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  2. Replies: 1
    Last Post: 05-17-2013, 12:53 PM
  3. Replies: 2
    Last Post: 08-30-2012, 07:59 AM
  4. Replies: 4
    Last Post: 11-10-2011, 03:41 PM
  5. Replies: 1
    Last Post: 08-19-2011, 12:16 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