Click here to Skip to main content
15,749,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i Have 2 tables
emp1 and emp2

now i want 2 insert in emp1 from emp2 which is UID field contains 0 value
if employee already exit in that emp1 table then it will automatically delete and newly add from emp2
Prakash Thirumoorthy 27-Feb-13 0:22am    
can u brief your table fields...? what if employee already exit? question is not clear... ?
AnnuBhai 27-Feb-13 0:37am    
emp code

begin try
	begin tran
		delete from emp1 where empid in
			select empid from emp2

		insert into emp1
		select * from emp2 where empid not in
			select empid from emp1
	commit tran
end try
begin catch
	rollback tran
	raiserror('transaction failed !', 16, 255)
end catch
Share this answer
AnnuBhai 27-Feb-13 0:56am    
wer i paste this code
AnnuBhai 27-Feb-13 0:56am    
AnnuBhai 27-Feb-13 1:21am    
actually i am using mysql
AnnuBhai 27-Feb-13 7:51am    
Condition also der

Fing1 not null and UID also not null

plz helpme yaar
AnnuBhai 27-Feb-13 7:52am    
i getting error in line insert statement
In SqlServer Stored Procedure.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900