spAddUpdate_Clients

Parameters

Parameter Parameter Type Mode Description
@PKID int INOUT
@CurrentUsersID int IN
@Name nvarchar(510) IN
@RESerialNumber nvarchar(100) IN
@OwnerID int IN
@HomePhoneType int IN
@BusinessPhoneType int IN
@EmailPhoneType int IN
@InterestsTypeID int IN
@Guid uniqueidentifier INOUT
@DefPrivacy smallint IN
@Address1 nvarchar(200) IN
@Address2 nvarchar(200) IN
@City nvarchar(200) IN
@PostCode nvarchar(20) IN
@OrigID nvarchar(20) IN
@options ntext IN
@OrganizationPhoneType int IN
@WebSitePhoneType int IN
@Phone1Type int IN
@Phone2Type int IN
@Phone3Type int IN
@Phone4Type int IN
@Phone5Type int IN
@Phone1TypeName nvarchar(50) IN
@Phone2TypeName nvarchar(50) IN
@Phone3TypeName nvarchar(50) IN
@Phone4TypeName nvarchar(50) IN
@Phone5TypeName nvarchar(50) IN
@LinkedInPhoneType int IN

Definition

Copy


                CREATE  procedure [dbo].[spAddUpdate_Clients]
                (
                    @PKID                    int output,
                    @CurrentUsersID            int,        
                    @Name                    nvarchar    (510),
                    @RESerialNumber            nvarchar(100),
                    @OwnerID                int,
                    @HomePhoneType            int,
                    @BusinessPhoneType        int,
                    @EmailPhoneType            int,
                    @InterestsTypeID        int,
                    @Guid uniqueidentifier    output,
                    @DefPrivacy              smallint,
                    @Address1                nvarchar(200),
                    @Address2                nvarchar(200),
                    @City                    nvarchar(200),
                    @PostCode                nvarchar(20),
                    @OrigID                    nvarchar(20),
                    @options                ntext,
                    @OrganizationPhoneType    int,
                    @WebSitePhoneType        int,
                    @Phone1Type                int,
                    @Phone2Type                int,
                    @Phone3Type                int,
                    @Phone4Type                int,
                    @Phone5Type                int,
                    @Phone1TypeName            nvarchar(50),
                    @Phone2TypeName            nvarchar(50),
                    @Phone3TypeName            nvarchar(50),
                    @Phone4TypeName            nvarchar(50),
                    @Phone5TypeName            nvarchar(50),
                    @LinkedInPhoneType        int = 0

                )
                as
                begin
                    begin transaction T1

                    if (@PKID<=0) begin
                        insert into dbo.Clients
                        (
                        [Name],
                        RESerialNumber,
                        OwnerID,
                        HomePhoneType,
                        BusinessPhoneType,
                        EmailPhoneType,
                        InterestsTypeID,
                        DefPrivacy,
                        Address1,
                        Address2,
                        City,
                        PostCode,
                        OrigID,
                        Options,
                        OrganizationPhoneType,
                        WebSitePhoneType,
                        Phone1Type,
                        Phone2Type,
                        Phone3Type,
                        Phone4Type,
                        Phone5Type,
                        LinkedInPhoneType
                        )
                        values
                        (
                        @Name,
                        @RESerialNumber,
                        @OwnerID,
                        @HomePhoneType,
                        @BusinessPhoneType,
                        @EmailPhoneType,
                        @InterestsTypeID,
                        @DefPrivacy,
                        @Address1,
                        @Address2,
                        @City,
                        @PostCode,
                        @OrigID,
                        @Options,
                        @OrganizationPhoneType,
                        @WebSitePhoneType,
                        @Phone1Type,
                        @Phone2Type,
                        @Phone3Type,
                        @Phone4Type,
                        @Phone5Type,
                        @LinkedInPhoneType
                        )

                        select @PKID = @@Identity
                        select @Guid = Guid from dbo.clients where [ID] = @PKID

                        exec spAuditThis @CurrentUsersID, 1, @Guid, 9

                        end
                    else 
                        begin
                        update [Clients] set
                        [Name]=@Name,
                        RESerialNumber=@RESerialNumber,
                        OwnerID=@OwnerID,
                        HomePhoneType=@HomePhoneType,
                        BusinessPhoneType=@BusinessPhoneType,
                        EmailPhoneType=@EmailPhoneType,
                        InterestsTypeID=@InterestsTypeID,
                        DefPrivacy = @DefPrivacy,
                        Address1 = @Address1,
                        Address2 = @Address2,
                        City = @City,
                        PostCode = @PostCode,
                        OrigID = @OrigID,
                        Options = @Options,
                        OrganizationPhoneType = @OrganizationPhoneType,
                        WebSitePhoneType = @WebSitePhoneType,
                        Phone1Type = @Phone1Type,
                        Phone2Type = @Phone2Type,
                        Phone3Type = @Phone3Type,
                        Phone4Type = @Phone4Type,
                        Phone5Type = @Phone5Type,
                        LinkedInPhoneType = @LinkedInPhoneType

                        where ID=@PKID

                        select @Guid = Guid from [Clients] where [ID] = @PKID

                        exec spAuditThis @CurrentUsersID, 2, @Guid, 9
                    end

                    if len(coalesce(@Phone1TypeName,''))>0 
                        update [ApplicationFields] set FieldName=@Phone1TypeName where FieldID=152

                    if len(coalesce(@Phone2TypeName,''))>0 
                        update [ApplicationFields] set FieldName=@Phone2TypeName where FieldID=153

                    if len(coalesce(@Phone3TypeName,''))>0 
                        update [ApplicationFields] set FieldName=@Phone3TypeName where FieldID=154

                    if len(coalesce(@Phone4TypeName,''))>0 
                        update [ApplicationFields] set FieldName=@Phone4TypeName where FieldID=155

                    if len(coalesce(@Phone5TypeName,''))>0 
                        update [ApplicationFields] set FieldName=@Phone5TypeName where FieldID=156

                    commit transaction T1
                end