title: SQL Server append query
body: <p>I have the following (not working) query:  </p>
  
  <pre><code>insert into [MyDB].[dbo].[Reports_StepsStat]  
      (ActivityID,TaskID,StepIndex,StepStatus,TimeSpanInSeconds,Score)
  VALUES (
    SELECT
      tasks.ActivityID as ActivityID,
      tasks.ID as TaskID,
      [StepIndex]=item.value('(StepIndex)[1]', 'NVARCHAR(MAX)'),
      [StepStatus]=item.value('(Status)[1]', 'NVARCHAR(MAX)'),
      [TimeSpanInSeconds] = DATEDIFF(MINUTE, item.value('(StartedOn)[1]',    'datetime'),item.value('(FinishedOn)[1]', 'datetime')),
      tasks.Score as Score
    FROM 
      [MyDB].[dbo].[Tasks] as tasks 
    CROSS APPLY 
      [Progress].nodes ('//Progress/Steps/ProgressStep') Progress(item)
  )  
  </code></pre>
  
  <p>The inner select query (<code>SELECT task.ActivityID..</code>) works perfectly and produces the expected table.  </p>
  
  <p>The outer <code>insert into</code> part is supposed to append the result of the inner part to a table by the name of <code>Reports_StepsStat</code>. This does not work.  </p>
  
  <p>I have tried and succeeded doing that with <code>SELECT INTO</code>, but apparently <code>SELECT INTO</code> can only be used to create a new table, and not to append to an existing table, which is what I need.  </p>
  
  <p>The errors I get are:  </p>
  
  <blockquote>
    <p><em>Msg 156, Level 15, State 1, Line 6</em><br>
    <em>Incorrect syntax near the keyword 'SELECT'.</em><br>
    <em>Msg 102, Level 15, State 1, Line 14</em><br>
    <em>Incorrect syntax near ')'.</em></p>
  </blockquote>