[dbo].[MssWebInsertUpdateScheduledMessage]
create procedure [dbo].[MssWebInsertUpdateScheduledMessage]
@inSakariScheduledMessageID int,
@inSakariConversationFID int,
@inSakariContactFID int,
@inTextMessage nvarchar(max),
@inCreatedAt datetimeoffset,
@inSentBy int,
@inToBeSentAt datetimeoffset
as
merge SakariScheduledMessage with( Tablock ) as target
using( select
@inSakariScheduledMessageID,
@inSakariConversationFID,
@inSakariContactFID,
@inTextMessage,
@inCreatedAt,
@inSentBy,
@inToBeSentAt) as source
(
SakariScheduledMessageID,
SakariConversationFID,
SakariContactFID,
TextMessage,
CreatedAt,
SentBy,
ToBeSentAt )
on(target.SakariScheduledMessageID = source.SakariScheduledMessageID)
when matched then
update
set target.TextMessage = source.TextMessage,
target.SentBy = source.SentBy,
target.ToBeSentAt = source.ToBeSentAt
when not matched then
insert(
SakariConversationFID,
SakariContactFID,
TextMessage,
CreatedAt,
SentBy,
ToBeSentAt )
values(
source.SakariConversationFID,
source.SakariContactFID,
source.TextMessage,
source.CreatedAt,
source.SentBy,
source.ToBeSentAt);
GO
GRANT EXECUTE ON [dbo].[MssWebInsertUpdateScheduledMessage] TO [MssExec]
GO