UFN_BANKACCOUNTADJUSTMENT_GETUNMAPPEDCOMPOSITESEGMENT_BYACCOUNTSYSTEM

returns 1 if there is a composite segment without default mapping

Return

Return Type
bit

Parameters

Parameter Parameter Type Mode Description
@PDACCOUNTSYSTEMID uniqueidentifier IN

Definition

Copy


        CREATE function dbo.UFN_BANKACCOUNTADJUSTMENT_GETUNMAPPEDCOMPOSITESEGMENT_BYACCOUNTSYSTEM
        (
        @PDACCOUNTSYSTEMID uniqueidentifier
        )
        returns bit
        with execute as caller
        as begin
            declare @BadFlag bit

        if exists (select V1.ID, V3.ID
              from
              (select t1.id, count(*) as TableCount
              from pdaccountstructure t1 inner join pdaccounttablesavailableforsegment t2 on t1.pdaccounttablesavailableforsegmentid = t2.id
              inner join pdcompositesegmenttablelist t3 on t2.tableid = t3.pdcompositesegmentid
              where t1.segmenttype = 4 and t1.PDACCOUNTSYSTEMID = @PDACCOUNTSYSTEMID
              group by t1.id) V1
              full outer join
              (select V2.ID, MAX(V2.SegmentCount) as SegmentCount
              from
                      (select t1.id, count(*) as SegmentCount
                      from pdaccountstructure t1 inner join pdcompositesegmentmapping t2 on t1.id = t2.pdaccountstructureid
                      inner join pdcompositesegmentmappingentry t3 on t2.id = t3.pdcompositesegmentmappingid and t3.isdefault = 1
                      where t1.segmenttype = 4 and t1.PDACCOUNTSYSTEMID = @PDACCOUNTSYSTEMID
                      group by t1.id, t3.PDCompositeSegmentMappingID) V2
                      group by V2.ID) V3
              on V1.ID = V3.ID
              where isnull(TableCount,0) != isnull(SegmentCount,0))
              set @BadFlag = 1
        else
              set @BadFlag = 0
            return @BadFlag
        end