UFN_GLACCOUNT_GETCATEGORY

Returns account category

Return

Return Type
uniqueidentifier

Parameters

Parameter Parameter Type Mode Description
@AccountNumber nvarchar(100) IN

Definition

Copy


create function dbo.UFN_GLACCOUNT_GETCATEGORY(@AccountNumber nvarchar(100))
returns uniqueidentifier 
WITH EXECUTE AS CALLER
AS
begin
    declare @SegNum int
    declare @SegStart int
    declare @SegLength int
    declare @SegValue nvarchar(30)
    declare @CatID uniqueidentifier

    select @SegNum = SEQUENCE from dbo.PDACCOUNTSTRUCTURE WHERE SEGMENTTYPE = 1

    select @SegLength = LENGTH,@SegStart = isnull((select sum(LENGTH) from dbo.PDACCOUNTSTRUCTURE where SEQUENCE < @SegNum),0) + @SegNum
    from dbo.PDACCOUNTSTRUCTURE
    where SEQUENCE = @SegNum

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


    if @SegValue  = ''
        exec dbo.UFN_RAISE_ERROR;
    else
        select @CatID = ID from dbo.PDCATEGORYDEFINITION  where FROMCODE <= @SegValue and  TOCODE >= @SegValue

    return @CatID

end