title: Inserting into Output table in an insert with from clausule
body: <p>I'm trying to duplicate some rows in a table, with a couple of changed values, and I also need to store an old (that will be lost) id to do further processing later. I'm trying to use the Output Clausule to store that information, but SQL Server is throwing the following error:</p>
  
  <pre><code>Msg 4104 &lt;...&gt; The multi-part identifier could not be bound.
  </code></pre>
  
  <p>This is the table I'm duplicating the data (slightly modified to reduce the number of columns):</p>
  
  <pre><code>Create Table Elements
  (
      id              int Identity(0,1)   not null, --PK
      name            varchar(50)         not null,
      modelID         int                 not null, --FK
  
      constraint PK_Elements primary key (id)
  );
  </code></pre>
  
  <p>And this is my my query:</p>
  
  <pre><code>declare @outputTable table 
  (
      oldElementID    int,
      id              int,
      name            varchar(50),
      modelID         bigint
  );
  
  Insert into Elements
  (name, modelID)
  Output e.id as oldElementID, 
      Inserted.id,
      Inserted.name,
      Inserted.modelID into @outputTable
  select e.name, @newModelID
  from Elements as e
  where e.modelID = @oldModelID
  </code></pre>
  
  <p><strong>Note</strong>: @oldModelID and @newModelID are previously declared and set.</p>
  
  <p>I'm not sure if my logic is wrong and I have to take a different approach (but I was sure it was possible to do it this way). Or if I simply have an error that I can't quite put my finger on it.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks!</p>