我有一个表,我想在向视图中添加新行时添加/更新,但我正在努力使其工作。
我的目标表是课程学习者进度,我的观点是Quiz_Results_For_Course_Learner_Progress
。
我已经从记录测验分数的表中创建了视图,并且由Zapier zap填充,因此我无法在该表中添加触发器 - 这就是为什么我创建了该表的视图。
我的触发器如下:
create trigger Update_Course_Progress_Quiz_Scores
on Quiz_Results_For_Course_Learner_Progress
instead of insert
as
declare @CompanyID int = (select CompanyID
from LEARNERS.dbo.ILR
where LEARNERID = LearnerID)
Merge Course_Learner_Progress as t
using inserted as s on t.CourseID = s.CourseID
and t.ModuleID = s.ModuleID
and t.LearnerID = s.LearnerID
and t.ContentID = s.ContentID
when not matched by Target then
insert (CompanyID, LearnerID, CourseID, ModuleID, ContentID, ContentType, Passmark, Score, [Status])
values (@CompanyID, s.LearnerID, s.CourseID, s.ModuleID,
s.ContentID, 4, s.Passmark, s.Quiz_Score, s.Status)
when matched then
update
set t.Score = s.Quiz_Score,
t.Status = s.[Status]
;
我可以成功创建触发器,但它不会在Course_Learner_Progress
表中插入/更新行。
我真的很欢迎这方面的帮助