January 19, 2011 at 7:12 am
Hi,
i have 2 tables emp_stage ,emp_dest ..I have some records in the emp_stage table.Now i want to insert thse records into the emp_dest table by satisfying the below mentioned conditions.
1)If there are same records found in both the tables then status field of emp_dest table should be updated to 'D'
2)If there are no matched records then that row should be inserte dinto the emp_dest table .
table1:emp_stage
empid ename dept status
100 sunny 10 N
100 sunny 10 N
200 deepak 20 N
then in my emp_dest table should be
empid ename dept status
100 sunny 10 D
200 deepak 20 N
January 19, 2011 at 10:09 am
Have a look in Books Online at the merge statement. It's what's called an upsert...update when present, otherwise insert. Hope that this helps.
Thanks...Chris
January 19, 2011 at 12:45 pm
If you dont have 2008 installed on your machine, then separate out the insert/update logic. But if you have 2008, Merge is the best option.
January 19, 2011 at 3:49 pm
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply