Select e.Category, e.EnteredBy, rtrim(u.UserLastName) + ',' + u.UserFirstName as FullName, COUNT( case when r.checkid =0 then 1 end) as chkcnt, -- comma here COUNT(case when r.CheckId= -1 then 1 end) as revcnt FROM ExpMaster as e INNER JOIN ReviewHistory as r ON r.XPID = e.origid INNER JOIN UserFile as u ON u.UserInit = e.EnteredBy WHERE e.EnteredBy = 'DAB' and e.EnteredDate between @mbDate and @mbEDate group by e.Category, e.EnteredBy, u.UserLastName, u.UserFirstName order by e.EnteredByIf you want to keep this dynamic, then use sp_executeSQL and parameters as is, take a look at this blog