I am having an issue trying to come up with a solution to return a table with the following stored procedure and then at the bottom being able to have a table row that shows the totals. Do I need to run a separate query for this...here is what I have:
Create PROCEDURE [dbo].[usp_me_totalquestion] @startDate datetime = NULL , @ENDDate datetime = NULL , @userid int = -1 , @groupByScript int = 0 , @groupByAgent int = 0 , @groupByDate int = 0 AS set nocount on begin DECLARE @sql VARCHAR(max) DECLARE @where VARCHAR(200) SELECT --[AgentName] = (CASE WHEN @userid > 0 THEN FullName ELSE 0 END), [scriptload] = count(*), [scriptread] = sum(CASE WHEN ScriptRead > 0 THEN 1 ELSE 0 END), [scriptreadpercent] = round(CASE WHEN count(*) = 0 THEN 0.00 ELSE (sum(CASE WHEN scriptread > 0 THEN 1 ELSE 0 END)/cASt(count(*) AS DECIMAL(6,2))) * 100 END,1), [cancelled] = sum(CASE WHEN STATUS = 'F' THEN 1 ELSE 0 END), [retained] = sum(CASE WHEN STATUS = 'S' THEN 1 ELSE 0 END) FROM ccp_customer_retention_log r inner join ccp_users u ON r.id = u.id WHERE r.insertdt between CAST(@startDate AS VARCHAR(15)) and CAST(@EndDate AS VARCHAR(15)) group by CASE WHEN @GroupByScript = 1 THEN r.scriptID WHEN @GroupByAgent = 1 THEN u.fullname