check if changed

  • okay so I'm pretty new to sql server and now I need to create a script that:

    compares the values of the row with the same id as the row with the update table(which has updated values in it) in which the price, description or replacement part have been changed.

    If they did change they should be updated and if they haven't been changed nothing should happen...

    ...but how on earth am I going to accomplish such a script

    Any help is always appreciated.

    Thanks 🙂

  • This SO thread shows how to write an UPDATE query using a join:

    http://stackoverflow.com/questions/3468006/sql-server-update-with-inner-join

    In other words, you join the table you want to update with the update table.

    Add a WHERE clause at the end that checks if a specific column has changed values or not.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • The UPDATE...JOIN construct can yield unexpected results. Usually a safer way to handle these tasks is using the MERGE statement because it protects you from updating the same row multiple times.

    MERGE (Transact-SQL) - SQL 2014

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply