Hi,
I have a trigger that updates my detail table. I would like to use the same trigger to also update the parent table based on a value in the detail table. I keep getting an error "The multi-part identifier "Citations.LogDetails.ParentLogNo" could not be bound."
The trigger works when I use a literal numeric value but not when I pass a value. Is there a way to pass the value from the detail table in the first update statement to the update statement in the second table?
Thanks
/****** Object: Trigger [Citations].[tgr_LogDetailsLastUpDated] Script Date: 9/14/2018 7:04:29 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [Citations].[tgr_LogDetailsLastUpDated]
ON [Citations].[LogDetails]
AFTER UPDATE AS
UPDATE Citations.LogDetails
SET LastUpdatedOn = GETDATE()
WHERE LogDetailID IN (SELECT DISTINCT LogDetailID FROM Inserted)
UPDATE Citations.LogHeader
SET LogHeader.TotPlatesPerLog = (SELECT COUNT(DISTINCT(VehiclePlate)) FROM Citations.LogDetails WHERE ParentLogNo = Citations.LogDetails.ParentLogNo)
WHERE LogHeader.INT_ID = Citations.LogDetails.ParentLogNo
ASKER