我正在尝试创建一个触发器,它将为已编辑的记录更新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'语句的哪种参数,因此它只编辑计划的描述我目前正在创建/更新?
我认为你需要加入INSERTED表,它保存所有修改过的记录
INNER JOIN INSERTED as I ON dbo.Subscriptions.Id = I.Id
而不是使用WHERE
子句,你应该INNER JOIN
到INSERTED表。这将只包含插入表中的行:
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;