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.
| Author |
Topic |
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2012-02-17 : 17:22:12
|
| Hi there,I have tabel1 and table2 which have exactly the same structures. I mean same cols and data types, etc. But table1 populated from SSIS import and table2 are filled from some ASP.NET codes based input. Now I need to compare if these two tables have the same data, here same means same rows and each field on a row should have same data. how can I do this? I mean compare them by sql secripts. Thanks in advance. |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-02-17 : 17:25:31
|
| Easiest method in SQL 2005 or higher:SELECT * FROM table1INTERSECTSELECT * FROM table2This will compare all columns in all rows in both tables and return those rows that exist in both. You can find more information on INTERSECT (and EXCEPT) here:http://msdn.microsoft.com/en-us/library/ms188055.aspxIf you have more complicated needs please post your table structure (DDL statement), some example data, and the results you're expecting. |
 |
|
|
allan8964
Posting Yak Master
249 Posts |
Posted - 2012-02-17 : 17:52:48
|
| Very cool, I just tested it works and I can use it for all cols and only one col. Thanks robvolk!!! |
 |
|
|
|
|
|