Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56

    Update Query - Multiple SETS and WHERE conditions

    I am having trouble getting this query to find records to update. I know there are matches because this was previously done in Excel.


    UPDATE tblTestData, tblBusinessRules1

    SET tblTestData.DESTINATIONSTATE = tblBusinessRules1.DESTINATIONSTATE
    AND tblTestData.DESTINATIONCITY=tblBusinessRules1.DEST INATIONCITY
    AND tblTestData.[#BUSRULE]=1

    WHERE ((tblTestData.NAMEFUNCTION=tblBusinessRules1.NAMEF UNCTION)


    And (tblTestData.CITY=tblBusinessRules1.CITY)
    And (tblTestData.ST=tblBusinessRules1.ST)
    And (tblTestData.COM4_DESC=tblBusinessRules1.COM4_DESC )
    And (tblTestData.USPORT=tblBusinessRules1.USPORT)
    And (tblTestData.FPORT=tblBusinessRules1.FPORT)
    And (tblTestData.ULTPORT=tblBusinessRules1.ULTPORT)
    And (tblTestData.SLINE=tblBusinessRules1.SLINE));

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    use comma instead of and for SET clause:
    SET tblTestData.DESTINATIONSTATE = tblBusinessRules1.DESTINATIONSTATE,
    tblTestData.DESTINATIONCITY=tblBusinessRules1.DEST INATIONCITY, tblTestData.[#BUSRULE]=1

  3. #3
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    I noticed that after I posted and it still doesn't work

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    what's wrong then?
    I found some space where there should not be, I am not sure if it's you typo when posting the thread:

    UPDATE tblTestData, tblBusinessRules1

    SET tblTestData.DESTINATIONSTATE = tblBusinessRules1.DESTINATIONSTATE
    AND tblTestData.DESTINATIONCITY=tblBusinessRules1.DEST INATIONCITY
    AND tblTestData.[#BUSRULE]=1

    WHERE ((tblTestData.NAMEFUNCTION=tblBusinessRules1.NAMEF UNCTION)
    And (tblTestData.CITY=tblBusinessRules1.CITY)
    And (tblTestData.ST=tblBusinessRules1.ST)
    And (tblTestData.COM4_DESC=tblBusinessRules1.COM4_DESC )
    And (tblTestData.USPORT=tblBusinessRules1.USPORT)
    And (tblTestData.FPORT=tblBusinessRules1.FPORT)
    And (tblTestData.ULTPORT=tblBusinessRules1.ULTPORT)
    And (tblTestData.SLINE=tblBusinessRules1.SLINE));

  5. #5
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    Must be a typo in the pasting.

    Here is where it stands now.

    UPDATE tblTestData, tblBusinessRules1 SET tblTestData.DESTINATIONSTATE = tblBusinessRules1.DESTINATIONSTATE, tblTestData.DESTINATIONCITY = tblBusinessRules1.DESTINATIONCITY, tblTestData.[#BUSRULE] = 1
    WHERE ((tblTestData.NAMEFUNCTION=tblBusinessRules1.NAMEF UNCTION) And (tblTestData.CITY=tblBusinessRules1.CITY) And (tblTestData.ST=tblBusinessRules1.ST) And (tblTestData.COM4_DESC=tblBusinessRules1.COM4_DESC ) And (tblTestData.USPORT=tblBusinessRules1.USPORT) And (tblTestData.FPORT=tblBusinessRules1.FPORT) And (tblTestData.ULTPORT=tblBusinessRules1.ULTPORT) And (tblTestData.SLINE=tblBusinessRules1.SLINE));

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    what error did you get?

  7. #7
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    No error. I wish I did and maybe I could figure it out.

    It just says, "you are about to update 0 rows".

    And I know this isn't the case because out of the 19000 rows. Roughly 1200 should be updated based on the conditions in the BusinessRules1 table.

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    it must be because you criteria logic is not correct.

  9. #9
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    What do you mean by that? There must be a type mismatch in the WHERE conditions? I based this UPDATE off another simple one that worked. Also I haven't touched the field types in the database yet as its a fairly new one from migrated data. All the data was strictly imported as text fields.

    Here is my other update query that worked.

    UPDATE tblTestData, tblNamesTable SET tblTestData.NAMEFUNCTION = [tblNamesTable].CORRECTEDNAME
    WHERE ((([tblTestData].NAME)=[tblNamesTable].AKANAME));

    I've played with added [s in the current one too to no avail.

    If you PM me your email address I can probably email you the file if that would help. Thanks for your help. I see that you've been the one responding to most of the Update questions.

  10. #10
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Please make sure there is no NULL values in these fields:
    ((tblTestData.NAMEFUNCTION=tblBusinessRules1.NAMEF UNCTION) And (tblTestData.CITY=tblBusinessRules1.CITY) And (tblTestData.ST=tblBusinessRules1.ST) And (tblTestData.COM4_DESC=tblBusinessRules1.COM4_DESC ) And (tblTestData.USPORT=tblBusinessRules1.USPORT) And (tblTestData.FPORT=tblBusinessRules1.FPORT) And (tblTestData.ULTPORT=tblBusinessRules1.ULTPORT) And (tblTestData.SLINE=tblBusinessRules1.SLINE));

    as you may know, null=null is not true.

  11. #11
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    There are over 1300 business rules that when the conditions match from the WHERE clause, the CITY and STATE are written from the BusinessRules1 table to the TestData one.

    Out of all these I know one condition is met and should be "updated"

    I mean you can "update" a NULL field right.

  12. #12
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I mean that there is no record match your where criteria.

    all of 8 fields need to be matched( and no null), then record will be updated.

    are you sure the one which you think it should be updated has no null in any of these 8 fields in either table?

  13. #13
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    Positive.

    I can show you record #1 in the BusinessRules1 has a match at record #31 in the TestData table.

  14. #14
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Show me please.

  15. #15
    jasonbarnes is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2010
    Location
    NC
    Posts
    56
    Gotta run to lunch. I'm having trouble uploading but I'll get back to it when I get back. Can you PM your email and make it easier when we get back?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. iif statement with multiple conditions
    By ragsgold in forum Queries
    Replies: 7
    Last Post: 08-24-2011, 05:38 PM
  2. Selecting Unique SETS of rows in Access Query
    By dalessandroh in forum Queries
    Replies: 0
    Last Post: 11-09-2010, 10:42 PM
  3. multiple dcount update query
    By slothnet in forum Programming
    Replies: 5
    Last Post: 08-24-2010, 03:44 PM
  4. Replies: 5
    Last Post: 06-19-2010, 07:55 PM
  5. Expression with multiple conditions
    By techexpressinc in forum Queries
    Replies: 3
    Last Post: 06-19-2009, 08:33 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