UFN_NAMEFORMAT_35

Default name format.

Return

Return Type
nvarchar(700)

Parameters

Parameter Parameter Type Mode Description
@CONSTITUENTID uniqueidentifier IN
@LASTNAME nvarchar(100) IN
@FIRSTNAME nvarchar(50) IN
@MIDDLENAME nvarchar(50) IN
@TITLE nvarchar(100) IN
@SUFFIX nvarchar(100) IN
@SPOUSELASTNAME nvarchar(100) IN
@SPOUSEFIRSTNAME nvarchar(50) IN
@SPOUSEMIDDLENAME nvarchar(50) IN
@SPOUSETITLE nvarchar(100) IN
@SPOUSESUFFIX nvarchar(100) IN

Definition

Copy


            create function [dbo].[UFN_NAMEFORMAT_35](
                @CONSTITUENTID uniqueidentifier,
                @LASTNAME nvarchar(100),
                @FIRSTNAME nvarchar(50),
                @MIDDLENAME nvarchar(50),
                @TITLE nvarchar(100),
                @SUFFIX nvarchar(100),
                @SPOUSELASTNAME nvarchar(100),
                @SPOUSEFIRSTNAME nvarchar(50),
                @SPOUSEMIDDLENAME nvarchar(50),
                @SPOUSETITLE nvarchar(100),
                @SPOUSESUFFIX nvarchar(100))
            returns nvarchar(700)
            with execute as caller
            as
            begin
                declare @result nvarchar(700)
                set @result = ''

                declare @CLASSYEAR nvarchar(3);

                select 
                    @CLASSYEAR = case 
                        when not [PRIMARY].CLASSOF is null and len([PRIMARY].CLASSOF) = 4 then 
                            N'''' + right(cast([PRIMARY].CLASSOF as nvarchar(4)), 2)
                        when not [PRIMARY].CLASSOF is null and len([PRIMARY].CLASSOF) = 3 then 
                            N'''' + right(cast([PRIMARY].CLASSOF as nvarchar(4)), 2)
                        when not [PRIMARY].CLASSOF is null and len([PRIMARY].CLASSOF) = 2 then 
                            N'''' + cast([PRIMARY].CLASSOF as nvarchar(4))
                        when not [PRIMARY].CLASSOF is null and len([PRIMARY].CLASSOF) = 2 then 
                            N'''' + cast([PRIMARY].CLASSOF as nvarchar(4))
                        else 
                            N'' 
                    end
                from dbo.EDUCATIONALHISTORY as [PRIMARY]
                where [PRIMARY].CONSTITUENTID = @CONSTITUENTID and [PRIMARY].ISPRIMARYRECORD = 1


                if len(@TITLE) > 0
                    set @result = @result + @TITLE + N' '

                if len(@FIRSTNAME) > 0
                    set @result = @result + @FIRSTNAME + N' '

                if len(@MIDDLENAME) > 0
                    set @result = @result + dbo.UFN_MAKEINITIALS(@MIDDLENAME) + N' '

                if len(@LASTNAME) > 0
                    set @result = @result + @LASTNAME + N' '

                if len(@SUFFIX) > 0
                    set @result = @result + @SUFFIX + N' '

                if len(@CLASSYEAR) > 0
                begin
                    if len(@SUFFIX) > 0
                        set @result = @result + N' ' + @CLASSYEAR + N' '
                    else
                        set @result = @result + N', ' + @CLASSYEAR + N' '
                end

                return replace(rtrim(ltrim(@result)), N' ,', N',')
            end