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 |
|
RPLI
Starting Member
3 Posts |
Posted - 2009-09-16 : 05:23:14
|
| Sir I have two tables name INDU and SUKI in sql server. Table name INDU contains column name policy_no, name, prem and table name SUKI contains column name policy_no, name, prem, to-date, from-date and sum. Now both the tables having data in all the columns. I wanted to compare both table's data and if data is same(matched) has to be separated along with all the columns(both INDU and SUKI table's columns)and has to be saved in another table called SATI. How to do this? Clearly I wanted to compare policy_no,name,prem from both INDU and SUKI table and if any matched data that has to be separated along full colum data of SUKI Table. |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2009-09-16 : 05:37:51
|
| [code]INSERT INTO SATI(policy_no , name , prem , to-date , from-date ,sum) SELECT s.policy_no, s.name, s.prem, s.to-date, s.from-date,s.sum FROM SUKI s JOIN INDU i ON s.policy_no = i.policy_no AND s.name = i.name AND s.prem = i.prem[/code] |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-09-16 : 06:03:27
|
| Declare @SATI Data as Table(Policy_no uniqueIdentifier,Name Varchar(50),Prem VarChar(50))Insert into @SATI(Policy_no, Name, Prem)Select CASE when i.Policy_No = s.Policy_No End AS Policy_No,CASE when i.Name = s.Name End AS Name,CASE when i.Prem = s.Prem End AS PremFrom INDU iLeft Join SUKI s on s.Policy_No = i.Policy_NoOrder By Policy_NoSelect *From @SATIThat should show you what you are after if I interpreted what you are getting at right. Not 100% sure what you are after. You would like what and how?! lol.What I have done should show you all the duplicates that you wanted to see?Let me know if that is what you are after. |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-09-16 : 06:05:19
|
| Dependant upon what exactly you are after they should both work |
 |
|
|
|
|
|
|
|