title: multiple operations of columns and a single scan SQL Server
body: <p>I have a table with <strong>200 columns (maybe more...)</strong></p>
  
  <pre><code>a1   a2   a3     a4  a5  ...a200
  ---------------------------------
  1.2  2.3  4.4   5.1  6.7... 11.9   
  7.2  2.3  4.3   5.1  4.7... 3.9   
  1.9  5.3  3.3   5.1  3.7... 8.9   
  5.2  2.7  7.4   9.1  1.7... 2.9  
  </code></pre>
  
  <p>I would like to compute many operations:</p>
  
  <ul>
  <li>SUM(every column)</li>
  <li>AVG(every column)</li>
  <li><strong>SQRT(SUM(every column))</strong></li>
  <li><strong>POWER(SUM(every column),2)</strong></li>
  <li><strong>MIN(all columns)</strong></li>
  <li><strong>MAX(all columns)</strong></li>
  <li><p><strong>GREATEST(SUM(one column) vs SUM(other column))</strong> 
  something like finding wich sum is greatest for every column:</p>
  
  <pre><code>a1 vs a2,  a1 vs a3, a1 vs a4....,a1 vs a200,
  a2 vs a1,  a2 vs a3, a4 vs a5....,a2 vs a200,  
  ...
  a200 vs a1, a200vs a2, a200vs a3.....a200 vs a199
  </code></pre></li>
  </ul>
  
  <p>If I do a single select statement for each column,and for each operation I'd have:</p>
  
  <pre><code>SELECT 
   SUM(a1),...,SUM(a200),
   AVG(Sum(a1)),...,AVG(Sum(a200)),
   POWER(Sum(a1),2),...,POWER(Sum(a200),2),
   GREATEST(SUM(a1),SUM(a2)), GREATEST(SUM(a1),SUM(a3)),...,GREATEST(SUM(a1),SUM(a200)),
   GREATEST(SUM(a2),SUM(a1)), GREATEST(SUM(a2),SUM(a3)),...,GREATEST(SUM(a2),SUM(a200))....
   GREATEST(SUM(a200),SUM(a1)), GREATEST(SUM(a200),SUM(a3)),...,GREATEST(SUM(a200),SUM(a199))
   etc... FROM tabMultipleColumns
  </code></pre>
  
  <p>The problem here is when I do a query with more than 1024 possible results
  aka, >= 1024 columns</p>
  
  <p>Is there a way to keep doing massive operations with data <strong>doing a single scan of the table</strong>, I mean avoiding doing multiple selects statements?</p>
  
  <blockquote>
    <p>I am trying to use only a scan, because if the table is huge (with size
    of many GB's) using many selects statements to scan the same table would be expensive...</p>
  </blockquote>
  
  <p>Can a tool like <code>BCP</code> be used or what solution do you think is more efficient...</p>
  
  <p>if you look only for the SUM, POWER(SUM(),2) and SQRT(SUM()), there are <code>600</code> result columns... if I keep doing this operations there are more than 1024...</p>