create procedure [dbo].[UpdateLastReadAt]
@inSakariContactPriKey int,
@inSysUserPriKey int
as
begin
;with insertUpdateSakariContactSysuserMap as
(
select
SysuserFID = @inSysUserPriKey,
SakariContactFID = @inSakariContactPriKey,
LastReadAt = sysdatetimeoffset()
)
merge SakariContactSysuserMap with (tablock)
using insertUpdateSakariContactSysuserMap on
SakariContactSysuserMap.SysUserFID = insertUpdateSakariContactSysuserMap.SysuserFID and
SakariContactSysuserMap.SakariContactFID = insertUpdateSakariContactSysuserMap.SakariContactFID
when matched then
update set
LastReadAt = insertUpdateSakariContactSysuserMap.LastReadAt
when not matched then
insert
(
SysuserFID,
SakariContactFID,
LastReadAt
)
values
(
insertUpdateSakariContactSysuserMap.SysuserFID,
insertUpdateSakariContactSysuserMap.SakariContactFID,
insertUpdateSakariContactSysuserMap.LastReadAt
);
end
GO
GRANT EXECUTE ON [dbo].[UpdateLastReadAt] TO [MssExec]
GO