title: Update data with existing table in loop
body: <p>I have a loop with a while statement, in the first step I created a table <code>#dane_wszystko</code> and then want to overwrite table <code>#dane_wszystko</code> with data from <code>#dane_wszystko</code> and data from <code>#dane_dzielone</code>.</p>
  <p>I have tried with many options, but all the time fails.</p>
  <pre><code>if @i = 1 
  begin
      select * into #dane_wszystko from #dane_dzielone
  end
  
  if @i &gt; 1
  begin
      ;with ctm as (
          select * from #dane_wszystko
          union all
          select * from #dane_dzielone
      )
      update #dane_wszystko
      set partycja = @i
      from ctm
  end
  </code></pre>