title: Setting the value of a column in SQL Server based on the scope_identity() of the insert
body: <p>I have a stored procedure in a program that is not performing well. Its truncated version follows. The <code>MyQuotes</code> table has an <code>IDENTITY</code> column called <code>QuoteId</code>. </p>
  
  <pre><code>CREATE PROCEDURE InsertQuote 
      (@BinderNumber VARCHAR(50) = NULL,
       @OtherValue VARCHAR(50))
  AS
      INSERT INTO MyQuotes (BinderNumber, OtherValue) 
      VALUES (@BinderNumber, @OtherValue);
  
      DECLARE @QuoteId INT 
      SELECT @QuoteId = CONVERT(INT, SCOPE_IDENTITY());
  
      IF @BinderNumber IS NULL 
          UPDATE MyQuotes 
          SET BinderNumber = 'ABC' + CONVERT(VARCHAR(10),@QuoteId)
          WHERE QuoteId = @QuoteId;
  
          SELECT @QuoteId AS QuoteId;
  </code></pre>
  
  <p>I feel like the section where we derive the binder number from the <code>scope_identity()</code> can be done much, much, cleaner. And I kind of think we should have been doing this in the C# code rather than the SQL, but since that die is cast, I wanted to fish for more learned opinions than my own on how you would change this query to populate that value. </p>