You can just add WITH ROLLUP to the end of the statement, like this:
Code:
SELECT Insurance AS InsuranceName, COUNT(*) AS PatientCount
FROM tblPatientVisits
WHERE (CheckedIn BETWEEN @BeginningDate AND @EndingDate) AND (ProviderName <> 'Walked Out')
GROUP BY Insurance WITH ROLLUP
then you will get an additional row where the InsuranceName column contains 'NULL' and the PatientCount column contains the "grand total".
If you have any nulls in your data, you will need to add a CASE statement to distinguish the actual Nulls from the "grand total" Null, like this:
Code:
SELECT CASE WHEN (GROUPING(Insurance) = 1) THEN 'TOTAL'
ELSE COALESCE(Insurance, 'NULL') END AS InsuranceName,
COUNT(*) AS PatientCount
FROM tblPatientVisits
WHERE (CheckedIn BETWEEN @BeginningDate AND @EndingDate) AND (ProviderName <> 'Walked Out')
GROUP BY Insurance WITH ROLLUP
Just realised this is the general SQL Language forum, but what I've posted here applies to SQL Server. What RDBMS do you need this query for?
rgds
Phil