Results 1 to 5 of 5
  1. #1
    yossik is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Oct 2013
    Posts
    2

    Cool running multiple updates at same time

    Hi



    I have a multiple (over 300!) 'Update XXX set YYY' commands to run . all for the same table and field, but with different criteria. something like
    update XXX set Y= a where W=3 and Z =4;
    update XXX set Y= b where W=5 and Z =6;
    update XXX set Y= a where W=8 and Z =10;

    I can run them separately. But is there a way to run them at one time?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    2 thoughts, either putting those three fields in a table you can join on or creating a function that accepts the W and Z values and returns the Y.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Here's the demo for pabldy's first option -

    With a table of new values laid out like this -
    Code:
    tblNewVal
    WVal ZVal NewY
    3     4     a
    5     6     b
    8    10     a
    You can have a single update like this -
    Code:
    UPDATE MyTable AS T1, tblNewVal AS TN
    SET T1.Y = TN.NewY
    WHERE T1.W = TN.WVal
    AND T1.Z = TN.ZVal;
    But first check for dups in your conditions with something like this -
    Code:
    SELECT WVal, ZVal, Count(NewY)
    FROM tblNewVal
    GROUP BY Wval, ZVal
    HAVING Count(NewY) > 1;
    And check for unmet/unset conditions like this -
    Code:
    SELECT T1.W, T1.Z
    FROM MyTable AS T1 LEFT JOIN tblNewVal AS TN 
    ON T1.W = TN.WVal AND T1.Z = TN.ZVal
    WHERE TN.NewY Is Null;

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're not going to write the function too?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Nah, gotta leave some things to the novices...

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

Similar Threads

  1. Replies: 2
    Last Post: 01-11-2013, 01:19 PM
  2. Running multiple queries in form
    By daniejm in forum Forms
    Replies: 3
    Last Post: 01-02-2013, 08:45 AM
  3. Unbound text box real time updates
    By DB2010MN26 in forum Forms
    Replies: 14
    Last Post: 12-11-2011, 02:23 PM
  4. Running Access for multiple users
    By itm in forum Access
    Replies: 2
    Last Post: 09-08-2011, 08:29 AM
  5. Form_Current() running multiple times
    By caddcop in forum Forms
    Replies: 0
    Last Post: 04-01-2011, 09:00 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