USP_PLEDGE_FIXDEPENDENTSPLITS

Updates the splits for all payments and write-offs towards a pledge.

Parameters

Parameter Parameter Type Mode Description
@PLEDGEID uniqueidentifier IN
@CHANGEAGENTID uniqueidentifier IN
@CHANGEDATE datetime IN

Definition

Copy


            CREATE procedure dbo.USP_PLEDGE_FIXDEPENDENTSPLITS
            (
                @PLEDGEID uniqueidentifier,
                @CHANGEAGENTID uniqueidentifier,
                @CHANGEDATE datetime
            )
            as 
            set nocount on;

            declare @PLEDGECURSOR CURSOR

            -- update splits for write-offs

            declare @WRITEOFFID uniqueidentifier; 

            set @PLEDGECURSOR = cursor local fast_forward for 
                select ID 
                from dbo.FINANCIALTRANSACTION 
                where PARENTID = @PLEDGEID
                and TYPECODE = 20
                and DELETEDON is null;

            open @PLEDGECURSOR;
                fetch next from @PLEDGECURSOR into @WRITEOFFID;

                while @@FETCH_STATUS = 0
                begin
                    exec dbo.USP_WRITEOFF_FIXSPLITS @WRITEOFFID, @PLEDGEID, @CHANGEAGENTID, @CHANGEDATE;

                    fetch next from @PLEDGECURSOR into @WRITEOFFID;
                end

                --When a cursor is used, it should be explicitly closed/deallocated in case of blocking or USP running long

                close @PLEDGECURSOR;
            deallocate @PLEDGECURSOR;