title: Visual Studio SQL Server Insert Statement
body: <p>This is my Trigger. The first two UPDATE Statements work but, the UPDATE Student does not work. </p>
  
  <pre><code> "UPDATE Student SET PointsAccumulated = PointsAccumulated + @Points
              Where @StudentID = StudentID"
  
  
  CREATE TRIGGER [Trigger]
  ON [dbo].[Attendance]
  After insert 
  AS
  BEGIN
      DECLARE @EventID int
      Declare @StudentID nchar
      DECLARE @Points int
  
      SELECT @EventID=EventID from inserted
      SELECT @EventID = EventID, @Points = Points from Event
      SELECT @StudentID = StudentID from inserted
  
      Update Event SET Attendance = Attendance + 1 
          WHERE @EventID = EventID
  
      UPDATE Attendance SET Points = @Points
          Where @EventID = EventID
  
      UPDATE Student SET PointsAccumulated = PointsAccumulated + @Points
          Where @StudentID = StudentID
  </code></pre>
  
  <p>THE SOLUTION that worked for me from HLGEM :  </p>
  
  <pre><code>    Update E
      SET Attendance = Attendance + 1 
      FROM  Event  E
      JOIN Inserted I ON i.eventid = e.eventid
  
  
      UPDATE A 
      SET Points = e.points
      FROM Attendance  a
      JOIN Event  E ON a.EventID = e.EventID
      JOIN Inserted I ON i.EventID = e.EventID
  
  
      UPDATE S
      SET PointsAccumulated = PointsAccumulated + e.points
      FROM Student S 
      JOIN  Inserted I ON i.studentID = s.studentID
      JOIN Event  E ON i.eventid = e.eventid
  </code></pre>
  
  <p>Lessons Learned:
        In SQL Server, it is never appropriate to use a variable (other than a table variable) to grab what was changed in the table in a trigger as they do not work row-by row like triggers in some other databases 
       --HLGEM</p>