UFN_BBNC_GETMATCHINGPRIMARYBUSINESSID

Returns the ID of the specified constituent's primary business organization for NetCommunity.

Return

Return Type
uniqueidentifier

Parameters

Parameter Parameter Type Mode Description
@MAPID int IN
@ORGANIZATIONNAME nvarchar(100) IN

Definition

Copy


            create function dbo.UFN_BBNC_GETMATCHINGPRIMARYBUSINESSID
            (
                @MAPID int,
                @ORGANIZATIONNAME nvarchar(100)
            )
            returns uniqueidentifier
            as
            begin
                return
                (
                    select top (1)
                        [BUSINESS].[ID]
                    from
                        dbo.CONSTITUENT
                        left join dbo.RELATIONSHIP on CONSTITUENT.ID = RELATIONSHIP.RELATIONSHIPCONSTITUENTID
                        left join dbo.CONSTITUENT as BUSINESS on RELATIONSHIP.RECIPROCALCONSTITUENTID = BUSINESS.ID
                    where
                        [CONSTITUENT].[SEQUENCEID] = @MAPID
                        and [RELATIONSHIP].[ISPRIMARYBUSINESS] = 1
                        and upper([BUSINESS].[KEYNAME]) = upper(@ORGANIZATIONNAME)
                    order by
                        [RELATIONSHIP].[DATECHANGED] desc
                )
            end