Stored Procedures [dbo].[MssWebGetIncomingMessages]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inContactIdint4
@inAfterDatedatetimeoffset10
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
CREATE procedure [dbo].[MssWebGetIncomingMessages]
@inContactId int,
@inAfterDate DateTimeOffset = null
as
begin
    set @inAfterDate = isnull(@inAfterDate,dbo.udfMinDateTimeOffset());
    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 SakariIncomingMessage
    left outer join SakariContactSysuserMap on SakariIncomingMessage.SakariContactFID = SakariContactSysuserMap.SakariContactFID and
        SakariContactSysuserMap.SakariContactFID = @inContactId
    left outer join Sysuser on SakariContactSysuserMap.SysuserFID = Sysuser.SysUserID
    left outer join SakariContact on SakariContact.SakariContactID = SakariIncomingMessage.SakariContactFID
    where SakariIncomingMessage.SakariContactFID = @inContactId and
    SakariIncomingMessage.CreatedAt >= @inAfterDate
    order by SakariIncomingMessage.CreatedAt desc
End
GO
GRANT EXECUTE ON  [dbo].[MssWebGetIncomingMessages] TO [MssExec]
GO
Uses