Results 1 to 4 of 4

Thread: Update Query

  1. #1
    Star Lounger
    Join Date
    Jun 2009
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have the following query that identifies discrepancies between my staging and production data:

    SELECT staging.Property, staging.Year, staging.Month, staging.Account, staging.RoomRevenue, staging.RoomNights, staging.Guests
    FROM [production] INNER JOIN staging ON ([production].Year = staging.Year) AND ([production].Month = staging.Month) AND ([production].Property = staging.Property) AND ([production].Account = staging.Account)
    WHERE (((staging.RoomRevenue)<>[production].[RoomRevenue])) OR (((staging.RoomNights)<>[production].[RoomNights])) OR (((staging.Guests)<>[production].[Guests]));

    Let's say I have 1000 total records and the above query identifies 100 different records. When I try to update production with the above query, I keep getting an error that the query is not updatable? Any clues?

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    You are joining the two tables on four fields: Year, Month Property and Account. For this to result in an updateable query there needs to be a unique index on these four fields (which would be achieved if they were a joint key).
    You need this to be sure that a record in one table matches just one record in the other.
    Regards
    John



  3. #3
    Star Lounger
    Join Date
    Jun 2009
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi John. Thanks for the quick response! I'm not familiar with joint keys. Is this something I could accomplish in the current setup or am I out of luck?

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    You make a combination of fields a joint key, by selecting all the fields in the table design, and clicking the key button on the ribbon. See the following fictitious example.

    [attachment=90087:multiplekey.gif]

    But you won't be able to do it if there are duplicates across those four fields.
    Attached Images Attached Images
    Regards
    John



Posting Permissions

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