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 |
|
sent_sara
Constraint Violating Yak Guru
377 Posts |
Posted - 2012-01-20 : 06:16:34
|
Hi can anybody help the below requirement in query form.Requirment is i need to compare employee1 with employee2 where id is the primary key,the column value which is mismatch alone, i need to pickit up and insert into new tableEmployee1 id name age mstatus salary2 sasi 31 M 5003 uma 32 f 2505 radha 25 f 600Employee2 id name age mstatus salary2 sasi 32 M 5003 uma 32 M 1505 radha1 25 f 600final output should be:Employee1_id Employee1_name Employee1_age Employee1_mstatus Employee1_salary Employee2_id Employee2_name Employee2_age Employee2_mstatus Employee2_salary2 null 31 null null null null 32 null null3 null null f 250 null null null M 1505 radha null null null null radha1 25 null null |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-01-20 : 06:29:30
|
| [code]SELECT e1.id AS Employee1_Id, CASE WHEN e1.name = e2.name THEN NULL ELSE e1.name AS Employee1_name, CASE WHEN e1.age = e2. age THEN NULL ELSE e1.age AS Employee1_age, --- etc for each of your columnsFROM Employee1 e1 INNER JOIN Employee2 e2 ON e1.id = e2.id[/code] |
 |
|
|
sent_sara
Constraint Violating Yak Guru
377 Posts |
Posted - 2012-01-20 : 07:08:38
|
Thanks for your replyiam trying for dynamic query.can you help me outquote: Originally posted by sunitabeck
SELECT e1.id AS Employee1_Id, CASE WHEN e1.name = e2.name THEN NULL ELSE e1.name AS Employee1_name, CASE WHEN e1.age = e2. age THEN NULL ELSE e1.age AS Employee1_age, --- etc for each of your columnsFROM Employee1 e1 INNER JOIN Employee2 e2 ON e1.id = e2.id
|
 |
|
|
|
|
|