One way is to UNION ALL 2 seperate statements together instead of using a compute clause. You should use the new join syntax. See if this works: (the derived table is just so that the sums will be the last row without the OrderCol column showing up in the result set.)select [Location] ,[# Discovered] ,[# Managed] ,[% Managed]from (--this derived table is not necessary for the union but just --so I could include a computed column for sorting that won't show up in results select 1 as orderCol, substring(dm.[Name],1,2) as [Location], count(distinct dm.[Name]) as [# Discovered], count(distinct w.[Name]) as [# Managed], count(distinct w.[Name])*100 / count(distinct dm.[Name]) as [% Managed] from DiscoveredMachines dm left join Wrksta w on dm.[Name] = w.[Name] where datediff(dd,dm.[DiscoveryDate],getdate()) < 90 and (dm.[Name] like 'AB%' or dm.[Name]like 'CD%' or dm.[Name] like 'AD%' or dm.[Name]like 'CB%' or dm.[Name] like 'SX%' or dm.[Name] like 'EX%') group by substring(dm.[Name],1,2) UNION ALL select 2 ,'total' ,count(distinct dm.[Name]) ,count(distinct w.[Name]) ,null ,null from DiscoveredMachines dm left join Wrksta w on dm.[Name] = w.[Name] where datediff(dd,dm.[DiscoveryDate],getdate()) < 90 and (dm.[Name] like 'AB%' or dm.[Name]like 'CD%' or dm.[Name] like 'AD%' or dm.[Name]like 'CB%' or dm.[Name] like 'SX%' or dm.[Name] like 'EX%') ) aorder by orderCol, [# Discovered] desc
Be One with the OptimizerTG