title: SQL Server query to stack columns vertically for summation, with multiple variables
body: <p>I have several columns that contain multiple variables and their associated values. I want to stack the Variable columns and their associated Value columns for summation.</p>
  
  <p>Each variable (eg ABC) may or may not appear in each column. There are about 200 variables (and their associated values) that may appear in 10 variable/value columns. I have just shown 6 variables in 3 variable/value pairs. </p>
  
  <p>Here are my columns:</p>
  
  <pre><code>Variable1   Value1  Variable2   Value2  Variable3   Value3
  ABC          1      ABC          9        ABC           6
  DEF          2      DEF          8        DEF           5
  XYZ          3      XYZ          7        XYZ           4
  KLM          4      KLM          6        KLM           3
  TUV          5                            TUV           2
                                            GHI           1
  </code></pre>
  
  <p>Here is my desired output: </p>
  
  <pre><code>VariableAll  ValueAll
  ABC           16
  DEF           15
  XYZ           14
  KLM           13
  TUV            7
  GHI            1
  </code></pre>
  
  <p>Any guidance you can provide would be greatly appreciated. Thank you for your help!</p>