Stored Procedures [dbo].[UpdateLastReadAt]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inSakariContactPriKeyint4
@inSysUserPriKeyint4
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
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
Uses