Further to my previous:
Here is a cursor solution which sort of solves problem, but as with cursors very very slow.
drop Procedure Alloc_Trans
go
Create Procedure Alloc_Trans
as
Begin
SET NOCOUNT ON;
DECLARE @cust_acct_no Varchar(20),@Trans_No Varchar(20),@Amount_Running...