title: TSQL - Insert values in table based on lookup table
body: <p>I have a master table in sql server 2012 that consists of two types. </p>
  
  <p>These are the critical columns I have in my master table:</p>
  
  <pre><code>TYPE    CATEGORYGROUP   CREDITORNAME    DEBITORNAME
  </code></pre>
  
  <p>One of those two types (Type B) doesn't have a CategoryGroup assigned to it (so it's always null).</p>
  
  <p>Type A always has a CategoryGroup and Debitor.</p>
  
  <p>Type B always has a Creditor but no CategoryGroup.</p>
  
  <p>For creditor and debitor I have two extra tables that also hold the CategoryGroup but for my task I only need the table for creditors since I already have the right value for type A (debitors).</p>
  
  <p>So my goal is to look-up the CategoryGroup in the creditor table based on the creditor name and ideally put those CategoryGroup values in my master table.
  With "put" I'm not sure if a view should be generated or actually put the data in the table which contains about 1.5 million records and keeps on growing.</p>
  
  <p>There's also a "cluster table" that uses the CategoryGroup as a key field. But this isn't part of my problem here.</p>
  
  <p>Please have a look at my sample <a href="http://sqlfiddle.com/#!3/c653b/1" rel="nofollow">fiddle</a></p>
  
  <p>Hope you can help me.
  Thank you.</p>