title: TSQL: Insert/Update with multiple tables/scope_identity()
body: <p>I have two tabs on my front end collecting information for Addresses and Users. Currently, my stored procedures are called on the final submit button. My Addresses table has an ID (primary key), Line1, and Line2 column. My Users table has an ID (primary key) FirstName, LastName and AddressID column (which should map to the ID column in the addresses table). My address insert proc looks like this:</p>
  
  <pre><code>ALTER PROC [dbo].[Addresses_Insert]
  @Line1 nvarchar(50),
  @Line2 nvarchar (50), = null
  @ID = INT output
  As
  BEGIN
  INSERT INTO [dbo].[Addresses]
             (                  
                  [Line1],
                  [Line2]
              )
       VALUES
             (@Line1, @Line2)
  
      SET    @Id = SCOPE_IDENTITY()
  
  
  END
  </code></pre>
  
  <p>My Users update looks like this:</p>
  
  <pre><code>ALTER PROC [dbo].[Users_Update]
       @Id int
      ,@FirstName nvarchar(50) = null
      ,@LastName nvarchar(50) = null
      ,@AddressId INT = null
  
  AS
  BEGIN
  UPDATE dbo.Users
  
  SET
       [FirstName] = @FirstName
      ,[LastName] = @LastName
      ,[AddressId] = @AddressId --not sure about this
  
  WHERE Id = @Id
  </code></pre>
  
  <p>I need to get the scope_identity() from the address stored procedure into the AddressID column for my Users table, but I'm not sure how to make that work.</p>