; with Bas ( select 7 as [Month],465318 as Code, 300 as budget union all select 9 as [Month],465318 as Code, 300 as budget),F as ( select 5 as [MOnth], 465318 as Code ,400 as ForeCast union all select 6 as [MOnth], 465318 as Code ,100 as ForeCast union all select 7 as [MOnth], 465318 as Code ,200 as ForeCast )

select B.*,F.foreCastfrom B inner join

(select code, max(ForeCAst) as ForeCast from F group by code )F on B.code=F.code