title: How to stack data with SQL Server
body: <p>Okay, so I have data with some large number of columns, say 400.</p>
  
  <pre><code>UID, ID, ID, var1, var2, . . . var400
  
  1, 23,  4651,  0,     0, . . .   1
  2, 47,  8567,  1,     1, . . .   5
  </code></pre>
  
  <p>I need it stacked so that it looks like this:</p>
  
  <pre><code>UID, ID, ID,    Variable,  Value
  1,   23, 4651    var1,       0
  1,   23, 4651    var2,       0
  . . .
  1,   23, 4651    var400,     1
  2,   47, 8567,   var1        1
  2,   47, 8567,   var2        1
  . . . 
  2,   47, 8567,   var400      5
  </code></pre>
  
  <p>There must be some relatively easy way to perform this transformation. But I can't think of what it is. Anyone have any ideas?</p>