title: c# clr udf scan sql table
body: <p>I want to create CLR UDF to scan a SQL table and read each column and sum all data for
  each column (I am working with big datasets, like <code>&gt;1000</code> columns and <code>20,000,000&gt;rows</code>).</p>
  
  <p>I'd like to compare applying for each column <code>SUM(COLUMN_NAME)</code> SQL function with parallelized <code>for loop</code></p>
  
  <p>So The SQL would look like </p>
  
  <pre><code>SELECT SUM(COLUMN_1),SUM(COLUMN_2),SUM(COLUMN_3),...,SUM(COLUMN_1000)
  </code></pre>
  
  <p>How can I do a <code>CLR UDF in C#</code> that would do that?</p>
  
  <p>I am planning to use an array, so each time I read the row I add it like:
   <code>array[i]+= sqlValue;</code></p>
  
  <p>How to do this, so I can execute both of them in a <code>stored proc</code>?</p>
  
  <p>Table</p>
  
  <pre><code>column_1  column_2 column_3   .... column_1000
  ---------------------------------------------
       451      57     253                 135
       251      77     356                 965
       481      15     323                 655  
       452      15     135                 665
      ... 
      ...20,000,000 more rows
  </code></pre>