Consulting

Results 1 to 4 of 4

Thread: Update without adding duplicates.

  1. #1
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    204
    Location

    Update without adding duplicates.

    No, not a simple DISCRETE problem:
    I have two tables, TableA And tableB
    TableA has a list of names, and the number of times each name has been added to the table. TableB has another list of names...some also on TableA, some not. I want to add those names from B to A that are NOT on A, but increase the number if times a duplicate would have been added.

    TableA
    Owen 5
    George 2
    Henry 1

    TableB
    Owen
    Smitty
    Harry

    TableA After process
    Owen 6
    George 2
    Henry 1
    Smitty 1
    Harry 1

    And sometimes I might want to REMOVE some names from TableA, and not All...ie. Owen might go from 6 to 5.

    Randy???

  2. #2
    VBAX Newbie
    Joined
    Oct 2008
    Posts
    5
    Location
    are you doing this in vba or in a query?

    you would use a "not in" query to get ones that were not in table a but in table b

  3. #3
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    204
    Location

    Using VBA

    I've done this in VBA, but think that it (might) be simpler in SQL.
    If I use a "not in", how do I increment (decrement) the count for the number of times a name has been entered into the table?

  4. #4
    Check the syntax, but this should give you the idea:

    currentproject.connection.excecute "INSTERT INTO TableA ([name]) SELECT ([name]) FROM TableB left join tableA on Tableb.name <> tableA.name where tablea.name is null"

    currentproject.connection.excecute "UPDATE TableA set [count] = count(name) from TableB where tablea.name = tableb.name"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •