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 |
rexyrexin
Starting Member
19 Posts |
Posted - 2011-09-21 : 13:53:12
|
I have a two tables, emp1, emp2.EMP1------empid empname number city------- ----------- -------- -----1 abc 987 delhi2 xyz 987 noida3 mnp blore4 def chennaiEMP2------empid empname number city------- ----------- -------- -----3 mnp 654 blore5 x12 noida4 def 159 chennai6 d09 chennai1 abc 987 delhiNow I want to update emp1 table with emp2 data. The columns matching should be updated and also those not appearing in emp1 should be added to emp1. There should be not any duplicate row in emp1. I can do it with MERGE statement in sql server 2008 but I dont want to do with it. Please give the solution which works in sql server 2005 and 2008 too. |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-09-21 : 14:23:55
|
Update first, joining on the empid, then do an insert into ... select .. where not exists and compare on the empid--Gail ShawSQL Server MVP |
 |
|
rexyrexin
Starting Member
19 Posts |
Posted - 2011-09-22 : 07:07:28
|
Thanks for help. it worked |
 |
|
|
|
|