Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Updating an Access database based on a sub-select

Updating an Access database based on a sub-select

Scheduled Pinned Locked Moved Database
databasequestionannouncement
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kyle Wood
    wrote on last edited by
    #1

    I have an Access database which contains every date between 01/01/2009 and 21/12/2029. In a 2nd column is a char value indicating whether the date is a working day or not. I need to decide whether xmas & boxing day fall on a non-working day and if so adjust the working day column value. I have the following to calculate the adjusted dates:

    SELECT switch((DATEPART("w",FullDate,2) In (6,7)),DATEADD("d",+2,FullDate),(DATEPART("w",FullDate,2) Not In (6,7)),FullDate)
    FROM UKWorkingDays
    WHERE DATEPART("m",FullDate,2)=12 And DATEPART("d",FullDate,2) In (25,26);

    If I wrap this in an update statement the SQL appears to execute but does nothing at all

    UPDATE UKWorkingDays SET WorkingDay = "B"
    WHERE FullDate in
    (

    SELECT switch((DATEPART("w",FullDate,2) In (6,7)),DATEADD("d",+2,FullDate),(DATEPART("w",FullDate,2) Not In (6,7)),FullDate)
    FROM UKWorkingDays
    WHERE DATEPART("m",FullDate,2)=12 And DATEPART("d",FullDate,2) In (25,26)

    );

    Can anyone give me any assistance please ?

    M 1 Reply Last reply
    0
    • K Kyle Wood

      I have an Access database which contains every date between 01/01/2009 and 21/12/2029. In a 2nd column is a char value indicating whether the date is a working day or not. I need to decide whether xmas & boxing day fall on a non-working day and if so adjust the working day column value. I have the following to calculate the adjusted dates:

      SELECT switch((DATEPART("w",FullDate,2) In (6,7)),DATEADD("d",+2,FullDate),(DATEPART("w",FullDate,2) Not In (6,7)),FullDate)
      FROM UKWorkingDays
      WHERE DATEPART("m",FullDate,2)=12 And DATEPART("d",FullDate,2) In (25,26);

      If I wrap this in an update statement the SQL appears to execute but does nothing at all

      UPDATE UKWorkingDays SET WorkingDay = "B"
      WHERE FullDate in
      (

      SELECT switch((DATEPART("w",FullDate,2) In (6,7)),DATEADD("d",+2,FullDate),(DATEPART("w",FullDate,2) Not In (6,7)),FullDate)
      FROM UKWorkingDays
      WHERE DATEPART("m",FullDate,2)=12 And DATEPART("d",FullDate,2) In (25,26)

      );

      Can anyone give me any assistance please ?

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Ew Access again - and a newer version than I have worked with. Some thoughts. Why do you have the switch (what is switch doing in SQL code) in the select portion, surely you want that in the where clause.

      Select Fulldate
      From UKWorkingDays
      Where fulldate in (filter 25/6) and weekday in (filter weekdays)

      I leave it to to grasshopper to fix the filter.

      K 2 Replies Last reply
      0
      • M Mycroft Holmes

        Ew Access again - and a newer version than I have worked with. Some thoughts. Why do you have the switch (what is switch doing in SQL code) in the select portion, surely you want that in the where clause.

        Select Fulldate
        From UKWorkingDays
        Where fulldate in (filter 25/6) and weekday in (filter weekdays)

        I leave it to to grasshopper to fix the filter.

        K Offline
        K Offline
        Kyle Wood
        wrote on last edited by
        #3

        Thanks for the reply Mycroft but I'm not sure that it is of much help. Take this year for example. 25/12 is a Friday, 26/12 is a Saturday so 28/12 is actually a holiday not a working day. My inner select statement returns 2 rows correctly containing Friday 25/12 and Monday 28/12. I then have to check every row in the table against these returned values and if equal mark the date as a non-working day (my outer update). The inner select works a treat so I thought an update statement where date in (inner select) would achieve what I wanted but for some reason it appears to do nothing, no rows returned updated and no exception thrown. Maybe its looping too many times and would eventually finish. I'll have to re-visit my code and see if there's a better way.

        1 Reply Last reply
        0
        • M Mycroft Holmes

          Ew Access again - and a newer version than I have worked with. Some thoughts. Why do you have the switch (what is switch doing in SQL code) in the select portion, surely you want that in the where clause.

          Select Fulldate
          From UKWorkingDays
          Where fulldate in (filter 25/6) and weekday in (filter weekdays)

          I leave it to to grasshopper to fix the filter.

          K Offline
          K Offline
          Kyle Wood
          wrote on last edited by
          #4

          More on this.. I've just stripped out all but this years dates and run my query which has done exactly as I expected and updated 25 & 28/12. I guess its just baulking at the number of repetitions it has to perform on the full table so I'm on the right track but do need to improve the code.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups