select card.*, DopCostAll = (select sum(isnull(DopCost,0)) from dbo.OCCostDop d where (d.InvNo = card.InvNo) and (d.dateDopCost <= @t)), from ocinvcard card
select card.*, CA.DopCostAll, CA.DopCostAll+card.SomeValue from ocinvcard card inner join (select InvNo,sum(isnull(DopCost,0)) as DopCostAll from dbo.OCCostDop d where d.dateDopCost <= @t group by InvNo) DCA on DCA.InvNo=card.InvNo
select card.*, t.DopCostAll from ocinvcard card join (select d.InvNo,sum(isnull(DopCost,0)) DopCostAll from dbo.OCCostDop d where d.dateDopCost <= @t group by d.InvNo) t on card.InvNo = t.InvNo