SQL Server compare two tables rows with identical columns and return changed columns
NickName:Anupam Sharma Ask DateTime:2012-11-17T16:35:56

SQL Server compare two tables rows with identical columns and return changed columns

I want to compare two tables with the same columns:

  • product - Id, Name, Description
  • Temp_Product - Id, Name, Description

Now update done by user will be saved into Temp_Product. When admin will see the details of that product I need to show the changes done by user. I want to compare both tables with a query and return columns that have changed from Product to Temp_Product.

Please suggest me better way to do this?

Copyright Notice:Content Author:「Anupam Sharma」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/13428993/sql-server-compare-two-tables-rows-with-identical-columns-and-return-changed-col

Answers
bummi 2012-11-17T08:47:09

Select p.id,p.name as orgn,t.name as altn,p.descripion as orgd,t.description as altd\nfrom product p\njoin tmp_product t\non t.id=p.id and (t.name<>p.name or t.description <> p.description)\n",


More about “SQL Server compare two tables rows with identical columns and return changed columns” related questions

SQL Server compare two tables rows with identical columns and return changed columns

I want to compare two tables with the same columns: product - Id, Name, Description Temp_Product - Id, Name, Description Now update done by user will be saved into Temp_Product. When admin will ...

Show Detail

SQL Server: compare columns in two tables

I've recently done a migration from a really old version of some application to the current version and i faced some problems while migrating databases. I need a query that could help me to compare

Show Detail

How to compare two columns in SQL server

I have two columns in SQL Server in two different tables. One column has 9.011, and other table columns has 9011. I need to remove the . and compare these two columns to see whether they are equa...

Show Detail

mssql compare two tables and only return non identical columns

I would like to know if two tables 'table1' and 'table2' are identical. I know I could compare every column of both tables in the 'where'-clause So this would basically show me every Row that is

Show Detail

comparing two tables with identical columns using T-SQL in SQL server

Scenario: need to compare two different tables with identical columns and need to load the different records into a new table with date and table name from which they are loaded. Data is loaded again

Show Detail

Swap columns from two sql server tables

I would like to know if there is anyway I can compare two columns in SQL Server. The two columns are located in two different tables. When the column 1's value is smaller than the column 2's valu...

Show Detail

compare two columns from two different tables in oracle sql for differences

Hi first time posting for SQL, I need to compare two different columns from two different tables in SQL. For example there is two tables and each have one column in them and I need to compare the...

Show Detail

Ensure 2 Columns in different tables are identical row by row MySQL

Im looking to compare two different tables row by row to ensure that both the file name and the count associated with the filename match. If either does not match I want to output the two rows that...

Show Detail

How to compare the columns of two tables, SQL Server?

I understand creating a join and comparing the values of specific columns from two tables. In this case, I am only interested in comparing the columns between two different tables, not the values. ...

Show Detail

SQL Server: adding rows/tables with the same columns

I have two tables in SQL Server and both of those tables have the same headers, which means its the same columns, but since I added them from Excel, it means that I was not able to import them as one

Show Detail