title: Count the records in a temp variable table
body: <p>I am trying to count the total records in a variable table, this is because I am also going to need to store the table in a sorted way. The entire point behind my problem is a query that will calculate the 90th percentile. I got this few steps from the internet: Order all the values in the data set from smallest to largest.</p>
  
  <p>Multiply k percent by the total number of values, n.</p>
  
  <p>This number is called the index.</p>
  
  <p>If the index obtained in Step 2 is not a whole number, round it up to the nearest whole number and go to Step 4a. If the index obtained in Step 2 is a whole number, go to Step 4b.</p>
  
  <p>4a.Count the values in your data set from left to right (from the smallest to the largest value) until you reach the number indicated by Step 3.</p>
  
  <p>The corresponding value in your data set is the kth percentile.</p>
  
  <p>4b.Count the values in your data set from left to right until you reach the number indicated by Step 2.</p>
  
  <p>My error...</p>
  
  <pre><code>1.DECLARE @TempMarks TABLE
  2.( 
  3.  mark float
  4.); 
  
  5.INSERT @TempMarks 
  6.SELECT mark 
  7.FROM Marks 
  8.ORDER BY mark ASC
  
  9.DECLARE @index float
  10.SET @index = 90 * COUNT( (SELECT (mark) FROM @TempMarks )) 
  </code></pre>
  
  <p>...comes in at line 10 :</p>
  
  <blockquote>
    <p>Cannot perform an aggregate function on an expression containing an
    aggregate or a subquery.</p>
  </blockquote>