I have not clearly understood your question, this may help if not exaplain what clarification you need pleaseDECLARE @MyCount intSELECT StudentID, COUNT(*) TotalCountFROM EventEnrollmentWHERE EventEnrollment.EnrollmentStatusCD='ENROLLED' GROUP BY StudentIDHAVING COUNT(*) > 0SELECT @MyCount = @@ROWCOUNT
You now have a recordset which has been output (two columns, Student ID and the COUNT of their number of enrollments. You also have a count (stored in @MyCount variable) of the number of rows that were in that recordset. You can output that as a separate recordset (i.e. a second recordset):SELECT @MyCount AS [Rows]or you could return it:RETURN @MyCountIf you do NOT want the first recordset AT ALL, but just want to know the number of rows in that recordset then:SELECT COUNT(*) AS [Rows]FROM( SELECT StudentID, COUNT(*) TotalCount FROM EventEnrollment WHERE EventEnrollment.EnrollmentStatusCD='ENROLLED' GROUP BY StudentID HAVING COUNT(*) > 0) AS X