title: How to use a function in a stored procedure sql server 2008
body: <p>I have a table </p>
  
  <pre><code>UserTime
  (
      UserTimeId(pk)
      ,DAY
      ,Date
      ,CheckIn
      ,CheckOut
      ,HOURS
  )
  </code></pre>
  
  <p>On run time when I click <code>CheckIn</code> button, it inserts current time</p>
  
  <pre><code>ALTER procedure [dbo].[InsertCheckIn]
     @UserID INT,
     @Day varchar(50),
     @Date nvarchar(50),
     @CheckIn nvarchar (50)
  as
  begin
      insert into UserTime (Userid, [Day], Date, CheckIn)
      values (@UserID, @Day, @Date, @CheckIn)
  end
  </code></pre>
  
  <p>and on checkout, I insert the current time. </p>
  
  <pre><code>ALTER procedure [dbo].[UpdateCheckOut]
     @UserID INT,
     @Day varchar(50),
     @Date nvarchar(50),
     @CheckOut nvarchar (50)
  as
  begin
      update UserTime
      set UserId   = @UserID
         ,[Day]    = @Day
         ,[Date]   = @Date
         ,CheckOut = @CheckOut
      from UserTime
      where UserId = @UserId
  end
  </code></pre>
  
  <p>I have a function </p>
  
  <pre><code> DATEADD(SECOND, - DATEDIFF(SECOND, @CheckOut, @CheckIn), @HoursWorked)
  </code></pre>
  
  <p>that take a difference of the time values stored.</p>
  
  <p>I want to store this difference in column <code>Hours</code>.</p>
  
  <p>When I insert CheckIn -> store current time. 
  On CheckOut, I want to store that time as well as the difference in <code>Hours</code>.</p>
  
  <p>How can I implement this? </p>