USP_PHONES_VALIDATEPHONES

USP_PHONES_VALIDATEPHONES

Parameters

Parameter Parameter Type Mode Description
@PHONES xml IN

Definition

Copy


            CREATE procedure dbo.USP_PHONES_VALIDATEPHONES(
                @PHONES xml
            ) as
                set nocount on;

                declare @PHONESTABLE table
                (
                    ID uniqueidentifier,
                    ISPRIMARY bit,
                    NUMBER nvarchar(100),
                    PHONETYPECODEID uniqueidentifier,
                    SEQUENCE int
                );

                insert into @PHONESTABLE(ID, ISPRIMARY, NUMBER, PHONETYPECODEID, SEQUENCE)
                    select ID, ISPRIMARY, NUMBER, PHONETYPECODEID, SEQUENCE
                    from dbo.UFN_CONSTITUENT_GETPHONES_FROMITEMLISTXML(@PHONES);

                declare @PRIMARYCOUNT int;

                select
                    @PRIMARYCOUNT = count(*)
                from @PHONESTABLE
                where ISPRIMARY = 1;

                if @PRIMARYCOUNT > 1 begin
                    raiserror('Only one primary phone number is allowed.', 13, 1)
                    return 1;
                end

                if @PRIMARYCOUNT < 1 and (select count(*) from @PHONESTABLE) != 0 begin
                    raiserror('You must mark at least one phone number as primary.', 13, 1)
                    return 1;
                end

                return 0;