; with result
as
(
select Product_Group, Product_Code, Product_Name, Sum(Stock) as Stock, Sum(Sale) as Sale, Sum(Amt) as Amt from #tmp
group by ROLLUP
(Product_Group,Product_code,Product_name)
)

select isnull(Product_Group,'Grand Total:'),(case when product_group is null and product_code is null then '' else isnull(Product_Code,'Sub-totals:') end) Product_code , isnull(Product_Name,'') as Product_Name, Stock, Sale, Amt
from result
where (product_name is not null and product_code is not null)or(product_name is null and product_code is null)