An aggregate may not appear in the WHERE clause( SQL Server Error )
<p>When I tried this query,</p>

<pre><code>select  
    (A.StudentId),
     max(A.StudentFirstName),
     max(A.StudentLastName),
     max(A.StudentAddress),
     'Batch ' + max(C.BatchName),
     CAST(MAX(CAST(A.StudentStatus as INT)) AS BIT),
     max(B.StudentBatchId) 
from 
    tblStudentDetails A  
inner join 
    tblStudentBatchDetails B on A.StudentId = B.studentid 
inner join 
    tblBatch C on C.BatchId = B.batchid 
where 
    max(A.StudentFirstName) like 'A%'
group by 
    A.StudentId
</code></pre>

<p>I got this error:</p>

<blockquote>
  <p>An aggregate may not appear in the WHERE clause unless it is in a
  subquery contained in a HAVING clause or a select list, and the column
  being aggregated is an outer reference.</p>
</blockquote>

<p>Can someone help to recover this problem?</p>