Stored Procedures [dbo].[MssWebSetAccountProfilePrimaryContact]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@orderIdint4
@contactIdint4
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
CREATE PROCEDURE [dbo].[MssWebSetAccountProfilePrimaryContact]
    @orderId int,
    @contactId int
AS
begin
    set nocount on

    ;with MergeData as
    (
        select OrderId = @orderId
        from Orders
        inner join AccountProfileContacts on
            Orders.AccountProfileFID = AccountProfileContacts.AccountProfileFID and
            AccountProfileContacts.AccountProfileContactID = @contactId
        where Orders.PriKey = @orderId

    ) merge AccountProfileOrderPrimaryContact with (tablock) using MergeData on
        AccountProfileOrderPrimaryContact.OrderFID = MergeData.OrderId
        when matched then update set AccountProfileContactFID = @contactId
        when not matched then insert
        (
            AccountProfileContactFID,
            OrderFID
        )
        values
        (
            @contactId,
            @orderId
        )
        ;
end
GO
GRANT EXECUTE ON  [dbo].[MssWebSetAccountProfilePrimaryContact] TO [MssExec]
GO
Uses