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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Updation in tables

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 delhi
2 xyz 987 noida
3 mnp blore
4 def chennai

EMP2
------
empid empname number city
------- ----------- -------- -----
3 mnp 654 blore
5 x12 noida
4 def 159 chennai
6 d09 chennai
1 abc 987 delhi

Now 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 Shaw
SQL Server MVP
Go to Top of Page

rexyrexin
Starting Member

19 Posts

Posted - 2011-09-22 : 07:07:28
Thanks for help. it worked
Go to Top of Page
   

- Advertisement -