UFN_GLACCOUNT_SEGMENTVALUES2

Returns the individual segments from the account number.

Return

Return Type
varchar(30)

Parameters

Parameter Parameter Type Mode Description
@AccountNumber nvarchar(100) IN
@SegNum int IN
@AcctSysID uniqueidentifier IN

Definition

Copy


CREATE function [dbo].[UFN_GLACCOUNT_SEGMENTVALUES2](@AccountNumber nvarchar(100), @SegNum int, @AcctSysID uniqueidentifier )
      returns varchar(30)
      as
      begin

      declare @SegStart int
      declare @SegLength int
      declare @SegValue nvarchar(30)

      select @SegLength = LENGTH, @SegStart = isnull((select sum(LENGTH+case SEPARATORCODE when 6 then 0 else 1 end) from dbo.PDACCOUNTSTRUCTURE where PDACCOUNTSYSTEMID = @AcctSysID and SEQUENCE < @SegNum),0) + 1
      from dbo.PDACCOUNTSTRUCTURE
      where SEQUENCE = @SegNum and PDACCOUNTSYSTEMID = @AcctSysID

      if @SegLength is null
          set @SegValue = ''
      else
          set @SegValue = substring(@AccountNumber,@SegStart,@SegLength)

      return (@SegValue)
      end