This is what I have. It looks like MS’s example adn I can’t figure out why it’s not running. I get an Invaild column name ‘PlanID’ error on this line:
WHERE gm.PlanId = i.[PlandID]
I was under the impression INSERTED would contain the same fields as the Plan table. Maybe I’m way off – this is my first trigger!
PlanID is the primary key in the Plan table and is a foreign key to Measures. I’m basically looking to check when a row in Plan’s Status field is updated and then update the Status field in Measures.
CREATE TRIGGER utr_Plan_Cascade_Status
ON [dbo].[Plan]
for UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
IF(UPDATE([Status]))
BEGIN
UPDATE dbo.Measures
SET [Status]= i.[Status]
FROM dbo.Measures m, INSERTED i, DELETED d
WHERE m.PlanId = i.[PlandID]
END
END
Any help will be appreciated.
Why are you using old style joins?
You also don’t need the deleted table at all.
This should work for you
Just as a FYI..
IF(UPDATE([Status]))will fire if you do the followingperhaps you want to add
where m.Status <> i.Statusto your WHERE clauseAlso keep in mind that if that column is nullable you need to account for that in this where clause