为什么我做的触发器放在表上就不生效啊~求大神~~

ss_赊侈 2015-10-25 01:38:52
这个触发器测试了好久,只有放在icstockbill里面能生效,放在icstockbillentry不生效,放在t_log(日志表)也不生效,搞不懂啊~~~

set QUOTED_IDENTIFIER ON
go

ALTER trigger [updatebill] on [dbo].[t_Log]
for insert,update
as
begin
declare @FlogID int
select @FlogID=FlogID from inserted
--自动插入采购价格资料
if not exists(select 1
from icstockbill t3,icstockbillentry t2,t_SupplyEntry t1
where t2.finterid=t3.finterid and t2.fsourceinterid=0
and t1.FUsed=1
and t1.FSupID=t3.FSupplyID
and t1.FItemID=t2.fitemid
and t1.FQuoteTime=t3.fdate
and t1.FLastModifiedBy=t3.fbillerid
and t1.FLastModifiedDate=t3.fdate
and t2.fsourceinterid=0
and t2.finterid=t1.finterid
and t3.fbillno=(SELECT SUBSTRING(fdescription,4,9) from t_log where ffunctionid='K000601' and FlogID=@FlogID))
begin
INSERT INTO t_SupplyEntry(FBrNo,FUsed,FEntryID,FSupID,FItemID,FUnitID,FStartQty,FEndQty,
FPType,FPrice,FCyID,FDisCount,FLeadTime,
FQuoteTime,FDisableDate,FRemark, FLastModifiedBy,
FLastModifiedDate,finterid)select '0',1,(select max(fentryid)+1 from t_SupplyEntry),
t1.FSupplyID,t2.fitemid,t2.FUnitID,0,0.0000,1,t2.fprice,
1,0.000000,0,fdate,'2100-01-01','',t1.fbillerid,t1.fdate,t2.finterid
from icstockbill t1,icstockbillentry t2
where t1.finterid=t2.finterid and t2.fsourceinterid=0
and t1.fbillno=(SELECT SUBSTRING(fdescription,4,9) from t_log where ffunctionid='K000601' and FlogID=@FlogID)
end
if not exists(select t2.finterid from t_Supply t1,icstockbillentry t2,icstockbill t3
where t1.FBrNo=0 and t1.fsupid=t3.fSupplyid and t1.fitemid=t2.fitemid
and t1.fcurrencyid=1 and fpohighprice=0 and fptype=1 and t3.fbillno=(SELECT SUBSTRING(fdescription,4,9) from t_log where ffunctionid='K000601' and FlogID=@FlogID))
begin
insert into t_Supply (FBrNo,fsupid,fitemid,fcurrencyid,fpohighprice,fptype)
select 0,t3.fSupplyid,t2.fitemid,1,0,1
from icstockbill t3,icstockbillentry t2
where t2.finterid=t3.finterid
and t3.fbillno=(SELECT SUBSTRING(fdescription,4,9) from t_log where ffunctionid='K000601' and FlogID=@FlogID)
end
end
...全文
404 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
卖水果的net 2015-10-28
  • 打赏
  • 举报
回复
哪句没有生效? 还是整个 TRI 根本就没有执行 ? 可以在代码中适当的加一些日志。
ss_赊侈 2015-10-27
  • 打赏
  • 举报
回复
没用的,就算我把限制去掉了,还是不生效,触发器做的不是很成功,应该还有其他原因。用简单的逻辑是可以的,奇了个怪!
专注or全面 2015-10-25
  • 打赏
  • 举报
回复
你看看 if not exists(select 1 from icstockbill t3,icstockbillentry t2,t_SupplyEntry t1 where t2.finterid=t3.finterid and t2.fsourceinterid=0 and t1.FUsed=1 and t1.FSupID=t3.FSupplyID and t1.FItemID=t2.fitemid and t1.FQuoteTime=t3.fdate and t1.FLastModifiedBy=t3.fbillerid and t1.FLastModifiedDate=t3.fdate and t2.fsourceinterid=0 and t2.finterid=t1.finterid and t3.fbillno=(SELECT SUBSTRING(fdescription,4,9) from t_log where ffunctionid='K000601' and FlogID=@FlogID)) 这段逻辑,在其他两个表中是否成立,不成立自然不生效了
xiaoxiangqing 2015-10-25
  • 打赏
  • 举报
回复
先写一个简单的逻辑看可不可以?

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧