[dbo].[MssWebGetScheduledMessages]
CREATE procedure [dbo].[MssWebGetScheduledMessages]
@inContactId int,
@inAfterDate DateTimeOffset = null
as
begin
set @inAfterDate = isnull(@inAfterDate,dbo.udfMinDateTimeOffset());
select
Prikey = SakariScheduledMessage.SakariScheduledMessageID,
TextMessage = SakariScheduledMessage.TextMessage +
case when SakariUserSignature.Signature is null then ''
else char(13) + char(10) + SakariUserSignature.Signature
end,
SentAt = SakariScheduledMessage.ToBeSentAt,
SentBy = dbo.FormatFirstNameLastName(Sysuser.FIRSTNAME, Sysuser.LASTNAME),
WasRead =
convert(bit,
case
when SakariScheduledMessage.CreatedAt > SakariContactSysuserMap.LastReadAt then 0
else 1
end )
from SakariScheduledMessage
left outer join Sysuser on SakariScheduledMessage.SentBy = Sysuser.SysUserID
left outer join SakariContactSysuserMap on SakariContactSysuserMap.SakariContactFID = SakariScheduledMessage.SakariContactFID and
SakariContactSysuserMap.SakariContactFID = @inContactId and SakariContactSysuserMap.SysuserFID = Sysuser.SysUserID
left outer join SakariOutgoingMessage on SakariScheduledMessage.SakariScheduledMessageID = SakariOutgoingMessage.SakariScheduledMessageFID
left outer join SakariUserSignature on SakariScheduledMessage.SentBy = SakariUserSignature.SysuserFID
where SakariScheduledMessage.SakariContactFID = @inContactId and
SakariOutgoingMessage.SakariOutgoingMessageID is null and
SakariScheduledMessage.ToBeSentAt >= @inAfterDate
order by SakariScheduledMessage.ToBeSentAt desc
end
GO
GRANT EXECUTE ON [dbo].[MssWebGetScheduledMessages] TO [MssExec]
GO