帮助查询请 [英] Help in Query Please

查看:72
本文介绍了帮助查询请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


i有2张桌子

emp1和emp2



现在我想要2从emp2插入emp1,这是UID字段包含0值

如果员工已经退出该emp1表,那么它将自动删除并从emp2中新添加

hi
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

推荐答案

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


在SqlServer存储过程中。
In SqlServer Stored Procedure.


这篇关于帮助查询请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆