title: C# SQL stored procedure - returning ID
body: <p>I have the following SP:</p>
  
  <pre><code>ALTER Procedure [dbo].[SP_RegisterComp]
       @CompName varchar(100)
       ,@Check_In datetime
       ,@ID int output
  
  As
  Set NoCount On
  
  Update Host Set [Check_In]=@Check_In
                   Where [CompName]=@CompName 
  
  
  If @@RowCount=0
    Insert into Host values (@CompName, @Check_In)
    SET @ID=SCOPE_IDENTITY()
    RETURN @ID
  </code></pre>
  
  <p>This works fine. If a computer name already exists in the table then the check in time is updated else it will create a new record and return the ID.</p>
  
  <p>How would I go about getting the @id when the record is updated?</p>
  
  <p>Cheers,</p>
  
  <p>John</p>