may this:ALTER proc [dbo].[my_agging]asSelect i.custnmbr, SUM( Case when rmdtypal = 7 or rmdtypal = 9 then -1*i.curtrxam else i.curtrxam end) as CurrentBalance,SUM(case when datediff(day, i.glpostdt, getdate()) between 31 and 45 then i.ortrxamt else 0 end) as [31-45],SUM(case when datediff(day, i.glpostdt, getdate()) between 46 and 60 then i.ortrxamt else 0 end) as [46-60],SUM(case when datediff(day, i.glpostdt, getdate()) between 61 and 65 then i.ortrxamt else 0 end) as [61-65],SUM(case when datediff(day, i.glpostdt, getdate()) > 90 then i.ortrxamt else 0 end) as [Over-90]from MyTable1 as i inner join MyTable2 as c on i.custnmbr = c.custnmbrwhere curtrxam > 0 group by i.custnmbrorder by i.custnmbr