我有一个表,我想在将新行添加到视图时添加/更新该表,但我正在努力完成这项工作。
我的目标表是课程学习者进度,我的观点是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
table.
我真的很欢迎对此提供一些帮助