Stored Procedures [dbo].[MssWebGetOutgoingMessages]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inContactIdint4
@inAfterDatedatetimeoffset10
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
CREATE procedure [dbo].[MssWebGetOutgoingMessages]
@inContactId int,
@inAfterDate DateTimeOffset = null
as
begin
    set @inAfterDate = isnull(@inAfterDate,dbo.udfMinDateTimeOffset());
    select
        PriKey = SakariOutgoingMessage.SakariOutgoingMessageID,
        TextMessage = SakariOutgoingMessage.TextMessage,
        SentAt = SakariOutgoingMessage.CreatedAt,
        SentBy = dbo.FormatFirstNameLastName(Sysuser.FIRSTNAME, Sysuser.LASTNAME),
        MessageStatus = SakariMessageStatus.SakariMessageStatusName ,
        WasRead =
            convert(bit,
                case
                    when SakariOutgoingMessage.UpdatedInMssAt > SakariContactSysuserMap.LastReadAt then 0
                    else 1
                end),
        ErrorMessage = SakariOutgoingMessage.ErrorMessage,
        ErrorCode = SakariOutgoingMessage.ErrorCode
    from SakariOutgoingMessage
    left outer join Sysuser on SakariOutgoingMessage.SentBy = Sysuser.SysUserID
    left outer join SakariContactSysuserMap on  SakariContactSysuserMap.SakariContactFID = SakariOutgoingMessage.SakariContactFID and
    SakariContactSysuserMap.SakariContactFID = @inContactId and SakariContactSysuserMap.SysuserFID = Sysuser.SysUserID
    left outer join SakariContact on SakariContact.SakariContactID = SakariOutgoingMessage.SakariContactFID
    inner join SakariMessageStatus on SakariOutgoingMessage.SakariMessageStatusFID = SakariMessageStatus.SakariMessageStatusID
    where SakariOutgoingMessage.SakariContactFID = @inContactId and
    SakariOutgoingMessage.CreatedAt >= @inAfterDate
    order by SakariOutgoingMessage.CreatedAt desc
end
GO
GRANT EXECUTE ON  [dbo].[MssWebGetOutgoingMessages] TO [MssExec]
GO
Uses