Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:29:43+00:00 2026-05-23T11:29:43+00:00

Been reading this site for answers for quite a while and now asking my

  • 0

Been reading this site for answers for quite a while and now asking my first question!

I’m using SQL Server

I have two tables, ABC and ABC_Temp.

The contents are inserted into the ABC_Temp first before making its way to ABC.
Table ABC and ABC_Temp have the same columns, except that ABC_Temp has an extra column called LastUpdatedDate, which contains the date of the last update. Because ABC_Temp can have more than 1 of the same record, it has a composite key of the item number and the last updated date.

The columns are: ItemNo | Price | Qty and ABC_Temp has an extra column: LastUpdatedDate

I want to create a statement that follows the following conditions:

  1. Check if each of the attributes of ABC differ from the value of ABC_Temp for records with the same key, if so then do the update (Even if only one attribute is different, all other attributes can be updated as well)
  2. Only update those that need changes, if the record is the same, then it would not update.
  3. Since an item can have more than one record in ABC_Temp I only want the latest updated one to be updated to ABC

I am currently using 2005 (I think, not at work at the moment).

This will be in a stored procedure and is called inside the VBscript scheduled task. So I believe it is a once time thing. Also I’m not trying to sync the two tables, as the contents of ABC_Temp would only contain new records bulk inserted from a text file through BCP. For the sake of context, this will be used with in conjunction with an insert stored proc that checks if records exist.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:29:44+00:00Added an answer on May 23, 2026 at 11:29 am
    UPDATE
        ABC
    SET
        price = T1.price,
        qty = T1.qty
    FROM
        ABC
    INNER JOIN ABC_Temp T1 ON
        T1.item_no = ABC.item_no
    LEFT OUTER JOIN ABC_Temp T2 ON
        T2.item_no = T1.item_no AND
        T2.last_updated_date > T1.last_updated_date
    WHERE
        T2.item_no IS NULL AND
        (
            T1.price <> ABC.price OR
            T1.qty <> ABC.qty
        )
    

    If NULL values are possible in the price or qty columns then you will need to account for that. In this case I would probably change the inequality statements to look like this:

    COALESCE(T1.price, -1) <> COALESCE(ABC.price, -1)
    

    This assumes that -1 is not a valid value in the data, so you don’t have to worry about it actually appearing there.

    Also, is ABC_Temp really a temporary table that’s just loaded long enough to get the values into ABC? If not then you are storing duplicate data in multiple places, which is a bad idea. The first problem is that now you need these kinds of update scenarios. There are other issues that you might run into, such as inconsistencies in the data, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been reading this site for a few months, and gotten some great answers
I have been reading a lot of posts on this site regarding the usage
I have been altering a query for a while now, reading many posts on
Ok this is my first post on Stack Overflow I have been reading for
i have been reading this interesting article which is increasing my every growing confusion
I've been reading on this quite some time...and i'm puzzled - Can you help
I have been reading through this wonderful website regarding the recommended Python IDEs and
I've been reading similar questions to this issue and have been able to get
I've been reading through this tutorial for using a SQLite database within an iPhone
I've been reading questions on Stack Overflow for a few weeks now... this'll be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.