title: How to query a DataTable in memory to fill another data table
body: <p>I am trying to update a Microsoft report. What it does is write out how many clients where excluded from a conversion process and for what reason. Currently the program writes all of the deleted clients back to the server then queries it back to fill a specialty table with the results.</p>
  
  <p>Here is the current query:</p>
  
  <pre><code>SELECT  DeletedClients.Reason, 
          COUNT(DeletedClients.Reason) AS Number, 
          CAST(CAST(COUNT(DeletedClients.Reason) AS float) 
              / CAST(t.Total AS float) 
              * 100 AS numeric(4, 1)) AS percentage
  FROM DeletedClients CROSS JOIN
      (SELECT COUNT(*) AS Total
      FROM DeletedClients AS DeletedClients_1
      WHERE (ClinicID = @ClinicID)) AS t
  WHERE (DeletedClients.ClinicID = @ClinicID) 
      AND (DeletedClients.TotalsIdent = @ident)
  GROUP BY DeletedClients.Reason, t.Total
  ORDER BY Number DESC
  </code></pre>
  
  <p>What I would like to do is not write <code>DeletedClients</code> to the server as it already exists in memory in my program as a DataTable and it is just slowing down the report and filling the database with information we do not need to save.</p>
  
  <p><strong>My main question is this, Either :</strong> </p>
  
  <p>How do I query a data table to make a new in memory data table that has the same results as if I wrote out the the SQL server and read it back in with the query above?</p>
  
  <p><strong>OR</strong></p>
  
  <p>How in Microsoft Reports do you do a group by clause for items in a Tablix to turn <code>=Fields!Reason.Value</code> <code>=Fields!Number.Value</code> <code>=Fields!percentage.Value</code> into something similar to the returned result from the query above?</p>