title: How to Pivot on two columns in SQL Server
body: <p>Below is the data rows I have:</p>
  
  <pre><code>ID     Code      OtherCol
  7      Code1      NULL
  7      code2      NULL
  2      unk        NULL
  4      unk        NULL
  3      Code2      NULL
  3      Code3      NULL
  3      Code5      Other1
  5      Code4      NULL
  5      Code5      Other2
  </code></pre>
  
  <p>I am trying get this displayed as</p>
  
  <pre><code>ID name1 name2 name3 name4 name5 nameunk Othername
  2                                unk
  3        code2 code3       code5         Other1
  4                                unk                    
  5                    code4 code5         Other2
  7  code1 code2
  </code></pre>
  
  <p>I was able to pivot the first column but having a problem pivoting the second one.</p>
  
  <p>And also there is a <code>name</code> for a given <code>code</code>, but the value under <code>OtherCol</code> are random.</p>