title: How to have a table trigger get the current row PK
body: <p>I am trying to set a trigger to a table to update a column "Duration" that is the duration between the start and end date on the row.  However, whenever I insert/update the column, the trigger does not work because SCOPE_INDENTITY() keeps returning null.  How can I fix this?</p>
  
  <pre><code>ALTER TRIGGER [dbo].[CalcDuration]
  ON [dbo].[Event]
  AFTER INSERT, UPDATE, DELETE 
  AS
  
  DECLARE @STARTED datetime
  DECLARE @FINISHED datetime
  DECLARE @ID int
  
  SELECT @ID = SCOPE_IDENTITY()
  
  SELECT @STARTED  = [Date &amp; Time Started] FROM  dbo.Event WHERE [Event ID] = @ID
  SELECT @FINISHED = [Date &amp; Time Finished] FROM dbo.Event WHERE [Event ID] = @ID
  
  UPDATE dbo.Event 
  SET Duration = DATEDIFF (  hour, @STARTED, @FINISHED )
  WHERE [Event ID] = @ID
  </code></pre>