title: Update millions of records
body: <p>I'm using MS SQL and have a table with millions of activities from hundreds of cost centers for workorders. We would like to analyse the data according to our different management levels and our reporting structure. Therefore I'm trying to update the data with the records from the master data table.</p>
  
  <p>So far everything works fine but it's way too slow. This is how I do it at the moment:</p>
  
  <pre><code>UPDATE [Activity - E].dbo.td_Import
  SET [Sender.Type]               = tmp_CC.[Type],
      [Sender.Person Responsible] = tmp_CC.[Person Responsible],
      [Sender.Level1]             = tmp_CC.[Level 1],
      [Sender.Level2]             = tmp_CC.[Level 2],
      [Sender.Level3]             = tmp_CC.[Level 3],
      [Sender.Level4]             = tmp_CC.[Level 4],
      [Sender.Active]             = tmp_CC.[Active]
  
  FROM (  SELECT [Cost Center], [Type], [Person Responsible], [Level 1], [Level 2], [Level 3], [Level 4], [Active]
          FROM [Master Data - E].dbo.md_CostCenter md_CC
          WHERE (md_CC.[Record Invalid] LIKE '') OR (md_CC.[Record invalid] IS NULL)) tmp_CC  
  WHERE ([Sender.CC] LIKE tmp_CC.[Cost Center]) AND ([Sender.Type] IS }NULL)
  </code></pre>
  
  <p>I have to run similar code five times and it take about 90 minutes to update all records. Since the data should be provided to the management around the clock I have only a short window of about two hours to get the data, update all information and create individual reports for the managers (excel report, every report take about 10 minutes by macro).</p>
  
  <p>I was thinking about joining the data with the master data table but I got totally lost in all the tutorials. All I got was some temporary table but nothing was stored in my activity table (td_Import).</p>
  
  <p>Any advice for a beginner? Thanks a lot in advance.</p>
  
  <p>Chris</p>