22,210
社区成员
发帖
与我相关
我的任务
分享
select * from sysobjects where type = 'TR';
exec sp_helptext 'tr_test_update'
create trigger tr_test_update on PURTA
for update
as
if exists(select * from inserted left join PURTB on
inserted.单别=PURTB.单别 and inserted.单号=PURTB.单号 where A='' or B='')
begin
raiserror('“参考单别”或“参考单号”不能为空!',16,1)
rollback
end
但同时引发出另一个问题困扰我,如果是修改单据,某一行要控制的“参考单别”或“参考单号”漏写,则也会提示 '“参考单别”或“参考单号”不能为空!',造成修改后的整张单据都不能保存,必须要放弃整张单据,重新来修改。
[/quote]
哦 这个单据审核操作也是update操作是吧,那就和普通的update操作,没区别,所以不管是审核,还是更新,都会报错了。
如果在操作的时候,能区分审核,还是更新操作,就好了
select * from sysobjects where type = 'TR';
exec sp_helptext 'tr_test_update'
create trigger tr_test_update on PURTA
for update
as
if exists(select * from inserted left join PURTB on
inserted.单别=PURTB.单别 and inserted.单号=PURTB.单号 where A='' or B='')
begin
raiserror('“参考单别”或“参考单号”不能为空!',16,1)
rollback
end
create trigger tr_test_update on PURTA
for update
as
if update(审核码)--这个就是审核
begin
if exists(select * from inserted left join PURTB on
inserted.单别=PURTB.单别 and inserted.单号=PURTB.单号 where A='' or B='')
begin
raiserror('“参考单别”或“参考单号”不能为空!',16,1)
rollback
end
end
go
[/quote]
已经能达到效果,提示审核失败,
并且修改单据没完成也能保存,但“raiserror('“参考单别”或“参考单号”不能为空!',16,1)”是不是没有执行,怎么没有返回消息呢[/quote]
呵呵,其实对于单据修改,就是当修改的时候,虽然也触发了update触发器,但是什么也没有做,所以保存肯定是成功的哈create trigger tr_test_update on PURTA
for update
as
if update(审核码)--这个就是审核
begin
if exists(select * from inserted left join PURTB on
inserted.单别=PURTB.单别 and inserted.单号=PURTB.单号 where A='' or B='')
begin
raiserror('“参考单别”或“参考单号”不能为空!',16,1)
rollback
end
end
go
[/quote]create trigger tr_test_update on PURTA
for update
as
if update(审核码)--这个就是审核
begin
if exists(select * from inserted left join PURTB on
inserted.单别=PURTB.单别 and inserted.单号=PURTB.单号 where A='' or B='')
begin
raiserror('“参考单别”或“参考单号”不能为空!',16,1)
rollback
end
end
go