Hope you can assist.
Here is my table:
Declare @AmtToDistribute float = 500.00
DECLARE @TestTable TABLE(TempID INT IDENTITY(1, 1) NOT NULL,
VicID INT ,
VicOrderedAmt MONEY,
RemainingBalance MONEY,
DistPriority INT,
DistPercentOf DECIMAL(5, 2),
DistributionAmt MONEY
);
INSERT INTO @TestTable ([VicID], [VicOrderedAmt], [RemainingBalance], [DistPriority], [DistPercentOf], [DistributionAmt])
VALUES (2318, 5.00, 5.00, 1, 60.00, 0),
(2319, 50.00, 25, 1, 40.00, 0),
(2320, 500.00, 500.0, 2, 33.00, 0),
(2321, 500.00, 500.0, 2, 33.00, 0),
(2322, 500.00, 500.0, 2, 34.00, 0);
SELECT * FROM @TestTable;
I'm trying to find a query that allows me to distribute a dollar amount to each row in the 1st priority until those values reach zero and then jump to the next priority until those values reach zero. The catch is that the dollar amount has to be distributed based on the DistPercentOf column. For instance the 2 rows in priority 1 split the amount first with the VicID getting 60% of the amount until the VicOrderedAmt has been met, then the second VicId get 40% of the amount. After priority 1 amounts have been met, move to Priority 2.
I've seen a few posts, but they deal with just a single priority and I need to payoff one priority before moving to the next.
Thanks in advance.