select a.element, a.subelement, a.elementnum, a.Lead, a.TotalCost, a.OtherFunds, a.Budget, a.Period, convert(integer,isnull(SUM(l.amount),0)/1000) as expended, 00000000 as programmed into #Temp from RTA_Elements a left join TIP_Projects b on a.ElementNum = convert(integer,substring(b.RtaID,5,2)) left join TIP_Ledger l on b.TipID = l.tipid and l.Fundtype = 'RTA' group by a.element, a.subelement, a.elementnum, a.Lead, a.TotalCost, a.OtherFunds, a.Budget, a.Period order by elementnum select a.element, a.subelement, a.elementnum, a.Lead, a.TotalCost, a.OtherFunds, a.Budget, a.Period, convert(integer,isnull(SUM(p.amount),0)) as programmed into #Temp2 from RTA_Elements a left join TIP_Projects b on a.ElementNum = convert(integer,substring(b.RtaID,5,2)) left join TIP_ApprovedFunding p on b.TipID = p.tipid and p.Fundtype = 'RTA' group by a.element, a.subelement, a.elementnum, a.Lead, a.TotalCost, a.OtherFunds, a.Budget, a.Period order by elementnum update #Temp set programmed = (SELECT programmed from #Temp2 where #Temp.ElementNum = #Temp2.ElementNum) select * FROM #Temp