我正在尝试创建一个触发器,以针对已编辑的记录更新SSRS上的说明。
我正在尝试将日程表信息添加到屏幕上SSRS的“描述”列中,您可以在其中为报告分配日程表。
我有以下查询:
CREATE TRIGGER UpdateDescription
ON [dbo].[Subscriptions]
AFTER INSERT, UPDATE
AS
UPDATE dbo.Subscriptions
SET [Description] = a.Description + ' | Schedule: ' + d.Name
FROM dbo.Subscriptions a
LEFT JOIN dbo.Catalog b
ON a.Report_OID = b.ItemID
LEFT JOIN dbo.ReportSchedule c
ON b.ItemID = c.ReportID
LEFT JOIN dbo.Schedule d
ON c.ScheduleID = d.ScheduleID
WHERE
该触发器到位后,当我编辑报告时,它将更改所有报告的每个日程表的描述...。我可以在“ WHERE”语句的末尾添加什么样的参数,以便仅编辑描述我当前正在创建/更新的时间表?
答案 0 :(得分:1)
我认为您需要加入INSERTED表,该表包含所有已修改的记录
INNER JOIN INSERTED as I ON dbo.Subscriptions.Id = I.Id
答案 1 :(得分:0)
您应该WHERE
到INSERTED表,而不是使用INNER JOIN
子句。这将仅包含插入表中的行:
CREATE TRIGGER UpdateDescription
ON [dbo].[Subscriptions]
AFTER INSERT, UPDATE
AS
UPDATE dbo.Subscriptions
SET [Description] = a.Description + ' | Schedule: ' + d.Name
FROM dbo.Subscriptions a
INNER JOIN inserted i ON i.SubscriptionID = a.SubscriptionID
LEFT JOIN dbo.Catalog b ON a.Report_OID = b.ItemID
LEFT JOIN dbo.ReportSchedule c ON b.ItemID = c.ReportID
LEFT JOIN dbo.Schedule d ON c.ScheduleID = d.ScheduleID;