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 |
|
mike1973
Starting Member
46 Posts |
Posted - 2010-12-30 : 03:27:49
|
| Hello guys,i have 2 tables T1, T2 with the same structure in columns but may differ in rows. The structure is the following:ID, CompanyID, YearID, MonthID, EmpID, TotalMy Question is how i can find the Difference between the 2 tables WhereT1.Company=T2.Company AND T1.YeardID=T2.YearID ANDT1.MonthID=T2.Month ANDT1.EmpID=T2.EmpID |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-30 : 03:54:36
|
| select *from T1join T2 OnT1.Company=T2.Company AND T1.YeardID=T2.YearID ANDT1.MonthID=T2.Month ANDT1.EmpID=T2.EmpIDand T1.Total = T2.Totalwhere T1.EmpID <> T2.EmpIDselect *from T1full outer join T2 OnT1.Company=T2.Company AND T1.YeardID=T2.YearID ANDT1.MonthID=T2.Month ANDT1.EmpID=T2.EmpIDand T1.Total = T2.Totalwhere T1.EmpID is null or T2.EmpID is null==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-12-30 : 23:50:31
|
I didnot carry out testing but I feel that one of the two condition should not be there.quote: Originally posted by nigelrivett select *from T1join T2 OnT1.Company=T2.Company AND T1.YeardID=T2.YearID ANDT1.MonthID=T2.Month ANDT1.EmpID=T2.EmpIDand T1.Total = T2.Totalwhere T1.EmpID <> T2.EmpID==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
Regards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2010-12-31 : 01:00:05
|
quote: Originally posted by pk_bohra I didnot carry out testing but I feel that one of the two condition should not be there.quote: Originally posted by nigelrivett select *from T1join T2 OnT1.Company=T2.Company AND T1.YeardID=T2.YearID ANDT1.MonthID=T2.Month ANDT1.EmpID=T2.EmpIDand T1.Total = T2.Totalwhere T1.EmpID <> T2.EmpID==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy.
Regards,BohraI am here to learn from Masters and help new bees in learning.
Sorry - that one was meant to beselect *from T1join T2 OnT1.Company=T2.Company AND T1.YeardID=T2.YearID ANDT1.MonthID=T2.Month ANDT1.EmpID=T2.EmpIDwhere T1.Total <> T2.Total==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|