U8触发器有什么注意事项?
在库存单据上做了触发器,从项目档案更新一个表头自定义项值,验证效果正常。但是存货核算,正常单据记账报错,把触发器禁用了,正常单据记账就正常了。
请问需要怎么做触发器,才能不影响系统的功能,U8的触发器有哪些需要注意的事项。
附件是2个单据的触发器脚本,都是实现类似的功能。
CREATE TRIGGERxsckd_update_fitemss05
ON rdrecord32 --销售出库单主表
FOR INSERT,UPDATE
AS
BEGIN
if (select cDefine11 from rdrecord32 wherecCode=(select cCode from inserted) ) is null--如果销售流水号为空
begin
update rdrecord32 set cDefine13=NULL,cDefine3=NULLwherecDefine11 IS NULL --清空其他2个字段
end
else --如果销售流水号不为空
begin
update rdrecord32 set cDefine13=fitemss05.销售项目编码,cDefine3=fitemss05.客户名称 from fitemss05 --从项目目录“新销售流水号”中更新其它2个字段
wherecDefine11=fitemss05.citemcode and cCode=(select cCode from inserted)
end
END 附件下载好像要积分,我把代码贴出来:
CREATE TRIGGERqtckd_update_fitemss05
ON RdRecord09 --其他出库单主表
FOR INSERT,UPDATE
AS
BEGIN
if (select cDefine11 from RdRecord09 wherecCode=(select cCode from inserted) ) is null--如果销售流水号为空
begin
update RdRecord09 set cDefine13=NULL,cDefine3=NULLwherecDefine11 IS NULL --清空其他2个字段
end
else --如果销售流水号不为空
begin
update RdRecord09 set cDefine13=fitemss05.销售项目编码,cDefine3=fitemss05.客户名称 from fitemss05 --从项目目录“新销售流水号”中更新其它2个字段
wherecDefine11=fitemss05.citemcode and cCode=(select cCode from inserted)
end
END 本帖最后由 consofor 于 2022-9-17 13:56 编辑
CREATE TRIGGERqtckd_update_fitemss05
ON RdRecord09 --其他出库单主表
FOR INSERT,UPDATE ------ 不清楚更新触发有啥意义
AS
BEGIN
set nocount on ;----设置无返回信息
if update(cHandler ) ----更新条件
if (select cDefine11 from RdRecord09 wherecCode=(select cCode from inserted) ) is null--如果销售流水号为空
begin
update RdRecord09 set cDefine13=NULL,cDefine3=NULLwherecDefine11 IS NULL --清空其他2个字段
end
else --如果销售流水号不为空
begin
update RdRecord09 set cDefine13=fitemss05.销售项目编码,cDefine3=fitemss05.客户名称 from fitemss05 --从项目目录“新销售流水号”中更新其它2个字段
wherecDefine11=fitemss05.citemcode and cCode=(select cCode from inserted)
end
END
学习学习 附件是2个单据的触发器脚本,都是实现类似的功能。
consofor 发表于 2022-9-17 13:53
CREATE TRIGGERqtckd_update_fitemss05
ON RdRecord09 --其他出库单主表
FOR INSERT,UPDATE ---- ...
感谢您的答复!有一个条语句没看懂: if update(cHandler ),这个cHandler指什么?
再次请教。
consofor 发表于 2022-9-17 13:53
CREATE TRIGGERqtckd_update_fitemss05
ON RdRecord09 --其他出库单主表
FOR INSERT,UPDATE ---- ...
搞清楚了,是一个字段名;P
学习一下学习一下学习一下 学习一下学习一下学习一下 学习一下学习一下学习一下 学习一下 看来做个用友的系统管理员还真不简单:victory:
页:
[1]