Stored Procedures [dbo].[MssWebGetIncomingMessages]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inContactIdint4
@inSysUserIdint4
@inDatedatetimeoffset10
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
CREATE procedure [dbo].[MssWebGetIncomingMessages]
@inContactId int,
@inSysUserId int,
@inDate DateTimeOffSet = null
As
begin
    select
        PriKey = SakariIncomingMessage.SakariIncomingMessageID,
        TextMessage = SakariIncomingMessage.TextMessage,
        ReceivedAt = SakariIncomingMessage.CreatedAt,
        ReceivedFrom = SakariContact.ContactName,
        WasRead =
            convert(bit,
                case
                    when SakariIncomingMessage.ImportedIntoMssAt > SakariContactSysuserMap.LastReadAt then 0
                    else 1
                end )
    from SakariContactSysuserMap
    inner join SakariIncomingMessage on SakariIncomingMessage.SakariContactFID = SakariContactSysuserMap.SakariContactFID
    left outer join Sysuser on SakariContactSysuserMap.SysuserFID = Sysuser.SysUserID
    left outer join SakariContact on SakariContact.SakariContactID = SakariIncomingMessage.SakariContactFID
    where SakariContactSysuserMap.SakariContactFID = @inContactId and
        SakariContactSysuserMap.SysuserFID = @inSysUserId and
        ((@inDate is not null and SakariIncomingMessage.CreatedAt >= @inDate) or
        (@inDate is null))
    order by SakariIncomingMessage.CreatedAt desc
End
GO
GRANT EXECUTE ON  [dbo].[MssWebGetIncomingMessages] TO [MssExec]
GO
Uses