I want to update an entity in a table after a insert is done in another table. Here my current trigger which doesn't work.
ALTER TRIGGER [dbo].[UpdateLastValues]
ON [dbo].[MeasureValues] FOR INSERT
AS BEGIN
SET NOCOUNT ON;
DECLARE @MyValue AS nvarchar;
DECLARE @MyTimestamp AS datetimeoffset;
DECLARE @MyId AS nvarchar;
SELECT @MyValue = Value FROM INSERTED;
SELECT @MyTimestamp = Timestamp FROM INSERTED;
SELECT @MyId = MeasurePointId FROM INSERTED;
UPDATE [dbo].[MeasurePoints] SET [dbo].[MeasurePoints].[LastValue] = @MyValue, [dbo].[MeasurePoints].[LastEdit] = @MyTimestamp WHERE [dbo].[MeasurePoints].[Id] = @MyId
END
Measure Values receive new values. The latest values should be saved in MeasurePoints LastValue Column.