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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Query to get data comparing 2 tables
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

swapna.anu
Starting Member

3 Posts

Posted - 09/30/2011 :  09:22:20  Show Profile  Reply with Quote
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 - 09/30/2011 :  10:30:51  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000