Results 1 to 12 of 12
  1. #1
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402

    Convert 5 Update queries into one?

    Hi everyone



    I have 5 Update queies that i would like to combine into one if its possible

    the five queries i have are these

    DueCheckQuery
    UPDATE UNEXData SET UNEXData.OVERDUE = "Not Over Due"
    WHERE (((UNEXData.duedate)>=Date()));

    Due Today
    UPDATE UNEXData SET UNEXData.OVERDUE = "Due Today"
    WHERE (((UNEXData.DUEDATE)=Date()));
    DueNextWeekQuery
    UPDATE UNEXData SET UNEXData.OVERDUE = "Due Next Week"
    WHERE (((Year([DUEDATE])*53+DatePart("ww",[DUEDATE]))=Year(Date())*53+DatePart("ww",Date())+1));

    OverDueQuery
    UPDATE UNEXData SET UNEXData.OVERDUE = "OVER DUE"
    WHERE (((UNEXData.duedate)<=Date()));

    ThisWeekQuery
    UPDATE UNEXData SET UNEXData.OVERDUE = "Due This Week"
    WHERE (((Year([DUEDATE])*53+DatePart("ww",[DUEDATE]))=Year(Date())*53+DatePart("ww",Date())));This basically changes the text in a feild called "OVERDUE" based on the date of the feild "DUEDATE"

    Is it possible to combine all these into a single query? i was thinking about using IIF, but im not sure how to do this

    These querys run when my main form opens, if i am able to combine these into a single query am i correct in thinking that their will be a performance gain?

    Kind regards

    Steve

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    These querys run when my main form opens, if i am able to combine these into a single query am i correct in thinking that their will be a performance gain?
    I am not so sure about that, especially since they all have different criteria. You could loop through the whole recordset and check each one, but I doubt that would be more efficient.

    You could put all 5 Update Queries into a single Macro or Procedure, and run it all at once from there.

  3. #3
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi JoeM

    Many thanks for the reply
    i will try the procedure route and see how i get on.

    many thanks

    Steve

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Just curious WHY these are update queries. Seems they could be Select queries if you wanted to know Due/overdue status based on Dates.
    But we really don't know much about your business or application.

  5. #5
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Orange

    the feild "OverDue" is updated based on the "DueDate" feild, each time the main form opens, these querys run and the overdue feild is updated.
    the duedate is the customers duedue date which never changes.

    not sure if a select would do, as the textfeild "OverDue" needs to be updated

    Kind regards

    Steve

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I have to agree with Orange. I would use select queries since the field "OverDue" is a calculated field.

    not sure if a select would do, as the textfeild "OverDue" needs to be updated
    Why does the textfeild "OverDue" need to be updated if a select query will provide the same data?

  7. #7
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi ssanfu

    I'm not sure i understand how a select query would help me as i needed to update the text in the feild "overdue" to either "Due Today", "Due Next Week", Due This Week", "Order Late" perhaps i am not understanding

    what i have done that has seemed to help alot is to make sure these querys only run once per day, when the form opens the following code runs this has certainly improved the performace of the app


    'Find the last date this query ran, only runs once a day
    'if the date has changed run the following queries

    'Lookup the last date the querys ran

    Dim LastRunUpdateQuery As String
    LastRunUpdateQuery = DMax("UnexQueryDate", "UnexDueDateQueryLastRun")

    'the the date the querys ran is less that todays date, run them

    If LastRunUpdateQuery < Date Then
    MsgBox "The Systems Due Date Check Queries Have Been Run, This Only Happens The First Time This Form Opens"
    DoCmd.SetWarnings False

    DoCmd.OpenQuery "UNEXOverDueQuery", acViewNormal
    DoCmd.OpenQuery "UNEXThisWeekQuery", acViewNormal
    DoCmd.OpenQuery "UNEXNextWeekQuery", acViewNormal
    DoCmd.OpenQuery "UNEXDueTodayQuery", acViewNormal


    'Then Closes The Queries Before The Form Closes

    DoCmd.Close acQuery, "UNEXOverDueQuery"
    DoCmd.Close acQuery, "UNEXthisWeekQuery"
    DoCmd.Close acQuery, "UNEXNextWeekQuery"
    DoCmd.Close acQuery, "UNEXDueTodayQuery"


    'then insert the date into the UnexDueQueryDateLastRun table

    DoCmd.RunSQL "INSERT INTO UnexDueDateQueryLastRun ([UnexQueryDate])" & "VALUES(date())"
    DoCmd.GoToControl "search"
    DoCmd.SetWarnings True

    Else

    'if the date has not changed go to the search feild
    'MsgBox "System Has Already Been Updated"
    DoCmd.GoToControl "search"

    End If

    Kind Regards

    Steve

  8. #8
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    sdel_nevo,

    The point Steve and I are making is that there is no need to update a field to identify OverDue etc.
    You can determine, via logic, whether or not something is Due and when without ever updating a field.
    It seems the update is using a calculated field, and we try to avoid calculated fields.

  9. #9
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    To follow up on what Steve and Orange are saying, the general rule of thumb in Access is NOT to store anything that can be easily calculated "on-the-fly". Storing calculations like that violates the rules of Data Normalization and can undermine the data integrity and the dynamic nature of a database.

    See this for the Rules of Normalization: http://sbuweb.tcu.edu/bjones/20263/A...sDB_Design.pdf

  10. #10
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi Orange

    Many thanks for getting back, now i understand and will adapt my design accordingly.

    Hi JoeM
    many thanks for the link i will study that, i bet i have lots to change now

    many many thanks for the time you have taken helping me

    Kind regards

    Steve

  11. #11
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    many thanks for the link i will study that, i bet i have lots to change now
    My first "real database" I created many years ago, I had the same issue, and had to re-design the whole thing to normalize it. It was a pain-in-the-neck, but it was so much better and easier to work with when I finished. If it isn't designed properly, it is easy to program yourself into a corner and seemingly easy tasks can become difficult to perform.

  12. #12
    sdel_nevo is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2013
    Location
    Gloucester, UK
    Posts
    402
    Hi JoeM

    im loving access much more than i thought i would, but i think a redesign will be on the cards, i will study the PDF link and start the changes required.
    just when i think i have something nailed i turns out i took the wrong approach

    i love a learning curve i just hope it doesn't get to steep

    many thanks for your help
    Kind regards
    Steve

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

Similar Threads

  1. Update queries
    By ezz in forum Access
    Replies: 4
    Last Post: 01-04-2015, 06:16 PM
  2. Replies: 5
    Last Post: 06-17-2014, 12:11 AM
  3. Replies: 3
    Last Post: 04-28-2014, 03:17 PM
  4. convert sql to access queries
    By slimjen in forum Queries
    Replies: 6
    Last Post: 07-26-2012, 12:06 PM
  5. Convert QUERIES from ORACLE to ACCESS!?!
    By jas0214 in forum Queries
    Replies: 2
    Last Post: 04-23-2012, 07:22 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