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 |
|
ConBran
Starting Member
5 Posts |
Posted - 2005-06-10 : 10:22:17
|
| Hi All,I couldn't find this topic any where else, so my apologies if one like it has already been submitted.Basically I am tring to compare data in two different tables, in order to remove records with duplicate data and place them in a temporary table for analysis. The data that is being compared in the tables is the following:Warehouse_IDMarket_IDYearMonthBrochure_Code(both tables use the same field names)The SQL code I am using to do it is:SELECT * FROM Import where Brochure_Code IN(Select Brochure_Code from IDF) AND Market_ID in (Select Market_ID from IDF) AND Warehouse_ID in (Select Warehouse_ID from IDF) AND Year in (Select Year from IDF) AND Month in (Select Month from IDF)The problem is that the code seems to not be working, it is just moving everything to the other table (im usign this code in conjunction with a DTS Package). I have verified that the data ISN'T in the IDF table (the one we dont want to import the duplicates to), so I am guessing that I have managed to write the code incorrectly - although it looks fine to me!! But thats why I am here, I have obviously done something wrong and I was wondering if anyone could see what I have done wrong, or know an easier/better way to do what it is I am trying to do.If you need to know anything else, just let me know!!ConBranPS - I guess I should have mentioned that all 5 fields have to be the same, not just one of the 5!! |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-06-10 : 10:29:21
|
| Do all these tables have common field?Post your Table structureLook for Joins in Books OnlineMadhivananFailing to plan is Planning to fail |
 |
|
|
ConBran
Starting Member
5 Posts |
Posted - 2005-06-13 : 05:29:38
|
| Hi,The tables have the exact same structure (this is because I copied and pasted the table and just renamed it in order to save time), I can post the whole structure if you like, but there are a totaly of 23 Columns in each table, and I'm sure you dont want to see all them.As for common fields - I am trying to compare two records with the exact same structure, and I am basing my comparison on the five fields listed above. As I said before, I am looking for some code that compares those five fields in BOTH tables to find matching records. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-06-13 : 05:34:52
|
| [code]Select T1.* from Import T1 inner join IDF T2on T1.Brochure_Code =T2.Brochure_Code and T1.Market_ID =T2.Market_ID andT1.Warehouse_ID=T2.Warehouse_ID andT1.[year]=T2.[year] andT1.Month=T2.Month[/code]MadhivananFailing to plan is Planning to fail |
 |
|
|
ConBran
Starting Member
5 Posts |
Posted - 2005-06-13 : 10:22:29
|
| Thanks very much Medhivanan!!!That worked a absolute treat! Only the valid records are copied in now, the rest are discarded, thanks again!!! |
 |
|
|
|
|
|
|
|