UFN_ADJUSTMENTHISTORY_GETADJUSTEDSPLITS
Returns the splits after an adjustment, for reporting purposes.
Return
Return Type |
---|
nvarchar(max) |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@REVENUEID | uniqueidentifier | IN |
Definition
Copy
CREATE function dbo.UFN_ADJUSTMENTHISTORY_GETADJUSTEDSPLITS
(
@REVENUEID uniqueidentifier
)
returns nvarchar(max)
as
begin
declare @RESULT nvarchar(max);
declare @DESIGNATION nvarchar(512);
declare @AMOUNT money;
set @RESULT = N'';
if @REVENUEID is null
return @RESULT;
declare SPLIT_CURSOR cursor local fast_forward for
select
coalesce(dbo.UFN_DESIGNATION_BUILDNAME(DESIGNATIONID), ''),
AMOUNT
from dbo.REVENUESPLIT where REVENUEID = @REVENUEID;
open SPLIT_CURSOR;
fetch next from SPLIT_CURSOR into @DESIGNATION, @AMOUNT;
while @@FETCH_STATUS = 0
begin
if len(@DESIGNATION) <> 0
set @RESULT = @RESULT + ' ' + @DESIGNATION + ' (' + cast(@AMOUNT as nvarchar) + ')' + char(13) + char(10);
fetch next from SPLIT_CURSOR into @DESIGNATION, @AMOUNT;
end
--When a cursor is used, it should be explicitly closed/deallocated in case of blocking or USP running long
close SPLIT_CURSOR;
deallocate SPLIT_CURSOR;
return coalesce(@RESULT, '');
end