title: How to insert the result of this code into a existing table in SQL Server 2008 R2?
body: <p>I have to insert the output of this code into an already existing table. How can I achieve this? I did it, but the output is getting appended to the previous result of the table.</p>
  
  <p>Code:</p>
  
  <pre><code>DECLARE @KPI_BU TABLE (BU NVARCHAR(MAX)) 
  
  INSERT @KPI_BU 
  SELECT @BU 
  
  Declare @KTV table(Business_Unit nvarchar(max), KPI nvarchar(max),YTD_Plan money, Actual money, Deviation money, Year_Plan money )
  
  DECLARE BU_cursor CURSOR FAST_FORWARD FOR 
  SELECT BU FROM @KPI_BU 
  
  OPEN BU_cursor 
  FETCH NEXT FROM BU_cursor INTO @BU 
  
  WHILE @@FETCH_STATUS = 0 
  BEGIN 
  INSERT @KTV(Business_Unit, KPI, YTD_Plan, Actual, Deviation, Year_Plan) 
  EXEC dbo.SP_KPI_History @FiscalYear, @BU 
  
  FETCH NEXT FROM BU_cursor INTO @BU 
  END 
  
  CLOSE BU_cursor 
  DEALLOCATE BU_cursor 
  
  --SELECT * FROM @KTV
  </code></pre>
  
  <p>And if I provide </p>
  
  <pre><code>SELECT * 
  into KPI_History
  FROM @KTV
  </code></pre>
  
  <p>in place of the commented line it creates a new table and inserts the result into it. I want to insert the RESULT into already existing table. </p>
  
  <p><strong>Update</strong></p>
  
  <p>@Mikael;</p>
  
  <p>I don't know whether i was able to make u understand my question or not. Sorry for that.</p>
  
  <p>What i want is, Now i have two table with this columns:</p>
  
  <p>KPI_History with(Businessunit,KPI_Name,YTD,Actual,Deviation,..)</p>
  
  <p>KPI_codes with (KPI_Name, KPI_code)</p>
  
  <p>In <strong>KPI_history</strong> table i want to use the <strong>KPI_Code</strong> of <strong>KPI_Codes table</strong> instead of <strong>KPI_name</strong> of <strong>KPI_History table</strong>. As KPI_Names are too long strings and i have created short codes for the KPI_Names and valued them into KPI_Code. i.e. KPI_code table consist of the KPI names and the codes for the KPI_Names.</p>
  
  <p>So output should be:
  KPI_Table with (Businessunit,KPI_Name[It sholud contain codes from KPI_History table],YTD,etc.)</p>
  
  <p>Hope i was able to make you guys understand what i am asking for. :|</p>