Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Query to get data comparing 2 tables

Author  Topic 

swapna.anu
Starting Member

3 Posts

Posted - 2011-09-30 : 09:22:20
Hi

Can any one tell me how to write a query to get data from a table when joined with another table comparing all the columns data which has data containing varchar, int, datetime, bit, tinyint etc.

For eg:

Table A

Col1 Col2 Col3 Col4

1 ABC Test 01/09/2011

2 XYZ Test1 02/09/2011

3 PQR Test2 10/09/2011

Table B

Col1 Col2 Col3 Clo4

1 AAA Test 02/08/2011

2 XYZ Test1 02/09/2011

4 BBB Test5 01/10/2011

Expected Results as below

Col1 Col2 Col3 Col4

1 ABC Test 01/09/2011

3 PQR Test2 10/09/2011

I need to compare all the columns in both the tables and return

1. if something different in both the tables

2. if something missing in Table B which is in A but don't need the records if missing in A but available in B

Please let me know how to make this work. I am not looking only for joins but any query which will make this task easy and will be able to use inside SP.

Thanks in advance.

swapna.anu
Starting Member

3 Posts

Posted - 2011-09-30 : 10:30:51
Got this working using the below query

SELECT S1.* FROM (SELECT checksum(*) AS CheckSumVal, * FROM Table1) s1
LEFT JOIN (SELECT checksum(*) AS CheckSumVal FROM Table2) s2
ON s1.checksumVal = s2.checksumval
WHERE s2.checksumval is null

Thanks.
Go to Top of Page
   

- Advertisement -