1.执行存储过程
exec p_employee_same '2017-07-26','2017-07-26' 提示错误,如图
---dbo.hr_employee [ID]为主键
把exec 语句修改如下:
begin try
begin tran
exec p_employee_same '2017-07-26','2017-07-26'
commit tran
end try
begin catch
rollback tran
end catch
执行没有问题,因为alter存储过程 时没有事务嵌套、回滚,果断修改为:
ALTER proc [dbo].[p_employee_same](@begindate varchar(10),@enddate varchar(10))
as
begin
begin try
begin tran
insert into,,,,,,,,,,,,,,,,,,,,,,,,,,,
update ,,,,,,,,,,,,,,,,
commit tran
end try
begin catch
rollback tran
end catch
end
执行是没有报错,但是insert into 的值没有生效,因为insert into 里有union all 叠加插入,ID:342767 重复了,排除出来再执行,就insert完成了。