title: SQL Server 2008 r2 Create trigger
body: <p>I am new to triggers and am have some difficulties I am trying to create a trigger that when someone logs into our WMS it logs how long users have been logged into the WMS and how long they have been idle for. I originally created this a Stored Procedure and it works great but when I tried to turn it into a Trigger it either does nothing or returns an Error.</p>
  
  <p>I have tried putting the entire code into the trigger and just pointing the trigger at the Stored Procedure. </p>
  
  <p>This is my current code and nothing happens even though the basic criteria have been met.</p>
  
  <pre><code>Use WMS;
  Go
  
  Create Trigger ExpiredUsersRmv
  On LogFile
  For Insert
  As
  
  --Total Users before stored procedure runs
  Declare @TtlUsers Int
  Set @TtlUsers = '7';
  --Idle time limit
  Declare @iTime DateTime
  Set @iTime = '00:05:00';
  
  If 
  (
  Select COUNT(USERID)
  From dbo.LogFile
  )&gt;= @TtlUsers
  
  Begin
  
    Insert Into dbo.ExpiredIdleUsersRmvd
    Select Working, e.USERID, e.CMPNYNAM, USRCLASS, tTime, iTime, LoginDatestamp, GETDATE() As cTime
    From dbo.ExpiredTime e Join inserted i on e.USERID = i.USERID
    Where iTime &gt;= @iTime;
  
  End
  </code></pre>