How about this:
--== Test Data ==--
if object_id('tempdb..#Test') is not null
drop table #Test;
Create Table #Test
(
Valuedt Datetime,
TotalDue_Amount Numeric (12,2),
TotalRecieved_Amount Numeric (12,2),
Maintaince_Due Numeric (12,2),
InsDue Numeric (12,2),
Stationary_Due Numeric (12,2),
Travelling_Exp_Due Numeric (12,2),
Maintaince_Collection Numeric (12,2),
Ins_Collection Numeric (12,2),
Stationary_Collection Numeric (12,2),
Travelling_Exp_Collection Numeric (12,2)
);
/*
I have TotalDue_Amount which sum of all other due,
NOTE: TotalDue_Amount IS NOT THE SUM OF ALL OTHER DUE IN THE GIVEN TEST DATA.
*/
Insert Into #Test
Values (GETDATE(),2000,1000,500,200,100,50,0,0,0,0);
Insert Into #Test
Values (DateAdd(dd,1,GETDATE()),5000,4000,1000,500,500,100,0,0,0,0);
select * from #Test;
--== Suggested Solution ==--
update #Test
set Maintaince_Collection = (TotalRecieved_Amount * (Maintaince_Due/TotalDue_Amount)),
Ins_Collection = (TotalRecieved_Amount * (InsDue/TotalDue_Amount)),
Stationary_Collection = (TotalRecieved_Amount * (Stationary_Due/TotalDue_Amount)),
Travelling_Exp_Collection = (TotalRecieved_Amount * (Travelling_Exp_Due/TotalDue_Amount))
select * from #Test;
/*
I have TotalDue_Amount which sum of all other due,
And I have TotalRecieved_Amount ,
Now my requirement is,
I want to allocate this TotalRecieved_Amount to
Maintaince_Collection,
Ins_Collection,
Stationary_Collection,
Travelling_Exp_Collection
according to follwing due amount in following order,
Maintaince_Due,
InsDue,
Stationary_Due,
Travelling_Exp_Due
Kindly help in this requirement.
Kindly tell me if any more information is needed.
*/
Unless I'm missing something, TotalDue_Amount is not the sum of all other due in the test data provided.