title: Trigger to call a stored procedure
body: <p>I have a view which extracts specific data. See example below</p>
  
  <p><a href="https://i.stack.imgur.com/d8Tkk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d8Tkk.png" alt="enter image description here"></a></p>
  
  <p>I would now like to call a stored procedure whenever a new value is captured by the view when the LocationCode is 'MYS'. Probably a trigger to call a stored procedure? Not sure if this works?</p>
  
  <p>The stored procedure runs based on these columns - ID and ActivityDate, i.e. need to pass them as input  which can be obtained from the data in the view. The Stored Procedure output needs to be stored into a temp table.</p>
  
  <pre><code>EXEC dbo.spLocationEvents
  @ID = '314AS',
  @ActivityDate = '20 Jan 2020 12:00 AM'
  </code></pre>
  
  <p>The data needs to be captured in the temp table every time someone enters a activity for location code 'MYS'.</p>
  
  <pre><code>CREATE TRIGGER [dbo].[ActivityEvents_IR] ON [dbo].[ActivityEvents] 
  FOR INSERT 
  AS 
  BEGIN 
  SET NOCOUNT ON 
      IF (SELECT LocationCode FROM inserted) LIKE 'MYS' 
      Begin 
          Return 
      END 
      DECLARE @ActivityDate datetime = 'SELECT ' + 'ActivityDate' + ' FROM inserted 
      WHERE LocationCode=''MYS''' 
      DECLARE @ID int = 'SELECT ' + 'id' + ' FROM inserted WHERE LocationCode=''MYS''' 
      INSERT INTO [#TempActivityEvents] 
      EXEC dbo.spLocationEvents @ID = @ID, @Date = @ActivityDate 
  END 
  GO
  </code></pre>