UFN_GLACCOUNT_GETPARTIALACCOUNTSTRING

Returns a partial account string with the specified segment removed.

Return

Return Type
nvarchar(100)

Parameters

Parameter Parameter Type Mode Description
@PDACCOUNTSYSTEMID uniqueidentifier IN
@EXCLUDEID uniqueidentifier IN
@GLACCOUNTID nvarchar(36) IN

Definition

Copy


CREATE function dbo.UFN_GLACCOUNT_GETPARTIALACCOUNTSTRING
        (
        @PDACCOUNTSYSTEMID uniqueidentifier,
    @EXCLUDEID uniqueidentifier,
    @GLACCOUNTID nvarchar(36)
        )
        returns nvarchar(100)
        with execute as caller
        as begin
        declare @ACCTSTR nvarchar(101) = ''

    select @ACCTSTR = @ACCTSTR + (select  (T3.SHORTDESCRIPTION  + case T1.SEPARATORCODE when 6 then '' else SUBSTRING(T1.SEPARATOR, 0, 2) end)
      from dbo.PDACCOUNTSTRUCTURE T1 
      join dbo.PDACCOUNTSEGMENT T2 on T1.ID = T2.PDACCOUNTSTRUCTUREID
      join dbo.PDACCOUNTSEGMENTVALUE T3 on T2.PDACCOUNTSEGMENTVALUEID = T3.ID
      WHERE T1.PDACCOUNTSYSTEMID = @PDACCOUNTSYSTEMID
      and T2.GLACCOUNTID = cast(@GLACCOUNTID  as uniqueidentifier)
      and T1.ID !=  @EXCLUDEID

      order by T1.SEQUENCE asc


      for XML PATH(''))


    if (select top 1 SEPARATORCODE from dbo.PDACCOUNTSTRUCTURE where PDACCOUNTSYSTEMID = @PDACCOUNTSYSTEMID and ID != @EXCLUDEID order by SEQUENCE desc) != 6
        set @ACCTSTR = left(@ACCTSTR,len(@ACCTSTR)-1)      

     if exists(select 1 from  dbo.GLACCOUNT where ID = cast(@GLACCOUNTID  as uniqueidentifier) and nullif(ACCOUNTALIAS,'') is not null)
        select @ACCTSTR =ACCOUNTALIAS from  dbo.GLACCOUNT where ID = cast(@GLACCOUNTID  as uniqueidentifier) 


        return @ACCTSTR
        end