Finally i found the solution, here u go,
Select 1 [Id],1000[value] into TempA
Select 2[Id], 10 value, 1 parent into TempB
Insert into TempB
Select 3,9,1
union all
select 4,5,1
Select * From TempA;
Select * From TempB;
Select ROW_NUMBER() Over (Partition By Parent Order By B.Id) Rnum,B.*,A.value [PVal] into tempc From tempb B
join tempa A on a.id = b.parent
Select * From TempC;
Select *, PVal - (Select SUM(value) From tempc E Where E.parent = D.Parent AND E.Rnum <= D.Rnum) From tempc D