Results 1 to 5 of 5
  1. #1
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215

    Help Writing Date Change SQL Code

    So,



    I have an excel spreadsheet here that I want to be able to replicate in SQL. That is, to create the End_Date_Change and Start_Date_Change fields.
    Essentially, I have an Initiative field that lists initiatives ("projects", really). The status of these initiatives is given to me every reporting period, or "Period_Date". Associated with these Initiatives are Start Dates and End Dates of the initiative, along with a "Status" of the initiative field.

    A change in End/Start date implies that the particular initiative start/end date has changed. For the End Date change, the criteria is that a change isn't considered if the initiative status is "Complete", and the criteria for the Start Date Change is that the initiative status is considered "Not Started". If the criteria is met, then I just marked the fields with a "YES".

    I wrote excel code to help illustrate:

    For the End_Date_Change field-

    =IF(A3=A2,IF(AND(D3<>D2, E3 <> "Complete"),"YES",""),"")

    For the Start_Date_Change field-

    =IF(B3=B2,IF(AND(C3<>C2, E3 = "Not Started"),"YES",""),"")


    ROW Initiative Period Date Start_Date End_Date Status Submission End_Date_Change Start_Date_Change
    1 Initiative 1 1/1/2015 4/1/2015 8/31/2015 Not Started 1/15/2015
    2 Initiative 1 2/1/2015 5/1/2015 8/31/2015 Not Started 3/16/2015 YES
    3 Initiative 1 3/1/2015 5/1/2015 8/31/2015 In Process 4/15/2015
    4 Initiative 1 4/1/2015 5/1/2015 8/31/2015 In Process 5/15/2015
    5 Initiative 1 5/1/2015 5/1/2015 9/30/2015 In Process 2/15/2015 YES
    6 Initiative 1 6/1/2015 5/1/2015 10/1/2015 Complete 6/15/2015
    7 Initiative 2 1/1/2015 3/1/2015 10/1/2015 Not Started 1/15/2015
    8 Initiative 2 2/1/2015 4/1/2015 10/1/2015 In Process 3/14/2015
    9 Initiative 2 3/1/2015 4/1/2015 11/1/2015 In Process 2/15/2015 YES
    10 Initiative 3 1/1/2015 3/1/2015 10/1/2015 Not Started 1/15/2015
    11 Initiative 3 2/1/2015 4/1/2015 10/5/2015 Not Started 3/14/2015 YES YES
    12 Initiative 3 3/1/2015 4/1/2015 11/1/2015 In Process 2/17/2015 YES

    Any help is appreciate with writing this code!

    Thanks,

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    This makes no sense..
    IF(A3=A2

    A col =[ROW], ....THEY WILL NEVER EQUAL!


  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    This is each record pulling a value for comparison from another record of same table. Requires nested subquery. Review: http://allenbrowne.com/subquery-01.html#AnotherRecord

    Or domain aggregate function (DLookup, DMax, DMin, etc).
    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.

  4. #4
    McArthurGDM is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2014
    Posts
    215
    Ranman256, Column A begins with the Initiative field - sorry for that. I tried to exemplify what the rows were for the first column.

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Unlike Excel, Access cannot compare 'the next row' (like A2=A3).
    you must use a key or something that will individualize the record... [ key]=2 vs [key]=3

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

Similar Threads

  1. help writing code that will update a table
    By 24t42 in forum Programming
    Replies: 1
    Last Post: 02-18-2015, 08:21 PM
  2. Replies: 4
    Last Post: 12-09-2014, 02:01 AM
  3. Replies: 1
    Last Post: 10-28-2014, 06:36 AM
  4. Writing code on the fly - TransferSpreadsheet
    By IanT in forum Import/Export Data
    Replies: 1
    Last Post: 05-24-2012, 08:28 AM
  5. Replies: 7
    Last Post: 05-31-2011, 11:51 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