Update and append data in one table from data in another table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sandra Walsh
    New Member
    • Nov 2011
    • 62

    Update and append data in one table from data in another table

    Hello -

    I have a local table in my database called t_CompanyData that holds a subset of the fields in another table called dbo_INT_AUX_LIS TING.

    dbo_INT_AUX_LIS TING is a linked table via an ODBC connection. This is a table in our CRM system and the data in that table is updated constantly.

    I need to run a query to:
    1 - update the data in t_CompanyData with any updated data for related records in dbo_INT_AUX_LIS TING

    2 - append any NEW records in dbo_INT_AUX_LIS TING to t_CompanyData

    I wrote an query that updates data and adds any new records using the strategy at


    New records are being added to t_CompanyData. However, the value in dbo_INT_AUX_LIS TING.LISTING_ID field is not being added to t_CompanyData.IA_CompanyLIST ING_ID.

    I have verified that the LISTING_ID field in the dbo_INT_AUX_LIS TING table is a NUMBER datatype (not autonumber). It is a primary key.

    Code:
    UPDATE (dbo_INT_AUX_LISTING LEFT JOIN t_CompanyData 
    ON dbo_INT_AUX_LISTING.LISTING_ID = t_CompanyData.IA_CompanyLISTING_ID) 
    LEFT JOIN dbo_INT_AUX_DIRECTORY 
    ON dbo_INT_AUX_LISTING.OWN_DIR_ID = dbo_INT_AUX_DIRECTORY.DIRECTORY_ID 
    
    SET t_CompanyData.IA_CompanyLISTING_ID = [dbo_INT_AUX_LISTING].[Listing_ID], 
    t_CompanyData.COMPANY_NM = [dbo_INT_AUX_LISTING].[Company_NM],
    t_CompanyData.DIRECTORY_NM = [dbo_INT_AUX_Directory].[directory_NM];
    Any suggestions greatly appreciated.
    Sandra
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32662

    #2
    The settings of t_CompanyData.I A_CompanyLISTIN G_ID are of far more interest Sandra ;-) If this is an AutoNumber field for instance, it would fail.

    PS Congrats on a well prepared question. Such quality from newbie posters is as rare as the proverbial R-H S.

    Comment

    • Sandra Walsh
      New Member
      • Nov 2011
      • 62

      #3
      Thanks, NP ;)

      t_CompanyData.I A_CompanyLISTIN G_ID is a number - long integer.

      Any other clues I can send along?

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32662

        #4
        I'm grasping at straws here Sandra, but is it involved as a foreign index to another table maybe? Does it feature in the Relationships diagram?

        Frankly I'm surprised at the described behaviour.

        Comment

        • Sandra Walsh
          New Member
          • Nov 2011
          • 62

          #5
          dbo_INT_AUX_LIS TING is not part of the Relationships diagram.

          Here are a few images - hope this helps.





          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Why store the company name and directory name if they're already stored in the other tables? When you need them, you can just join the tables together.

            Comment

            • Sandra Walsh
              New Member
              • Nov 2011
              • 62

              #7
              When I first set up this database it was taking a very long time to load the data from the ODBC tables. They have done some upgrades to our servers and now things are nice and fast.

              I think it may be best for me to re-configure the back end to get data directly from the ODBC tables instead of going through this update/append process. Hopefully this wont be too much of a hassle :-)

              Thanks all!

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32662

                #8
                I see the relationship, but I cannot think of anything that would explain the bahaviour. Even if all the restrictions are set up the value, by definition, must be a valid one as it's the same as the one it's linked to (having been copied from it). I don't know the problem I'm afraid.

                Comment

                • Sandra Walsh
                  New Member
                  • Nov 2011
                  • 62

                  #9
                  Thanks NP - maybe some issues with the install. I have been having other strange problems so I might re-install Access.

                  Comment

                  Working...