title: Output field from another table on insert SQL Server
body: <p>I have a table <code>@p2</code> sent as parameter to a stored procedure that has an id named <code>IdObjectSubTypeTemp</code>, I need to insert in a table <code>ObjectSubType</code>and output the identity with the id of the parameter table as below:</p>
  
  <pre><code>INSERT INTO [dbo].[ObjectSubType]
      ([IdObject]
      ,[IdSubType])
  OUTPUT inserted.[IdObjectSubType] ,OS.[IdObjectSubTypeTemp]
  INTO @IdObjectSubTypeTbl
  SELECT OS.[IdObject] 
      ,OS.[IdSubType]
  FROM @p2 OS
  </code></pre>
  
  <p>But I keep getting that:</p>
  
  <blockquote>
    <p>The multi-part identifier "OS.IdObjectSubTypeTemp" could not be bound.</p>
  </blockquote>
  
  <p>although I did the same on update and it is working but on insert it's not working</p>