[dbo].[MssWebGetConversationListByUser]
CREATE procedure [dbo].[MssWebGetConversationListByUser]
@inSysUserId int
as
begin
set nocount on
select
OrderId = Orders.PriKey,
OrderNumber = coalesce(
Orders.OrderNo,
Orders.ArchivedOrderNo + ' [A]' ) ,
CustomerName = dbo.FormatFirstNameLastName(Orders.LastName, Orders.FirstName ),
ContactPriKey = SakariContact.SakariContactID,
UpdateCount = Data.UpdateCount ,
ScheduledMessageCount = Data.ScheduledMessageCount,
LastUpdatedAt = SakariContact.LastUpdatedAt
from UdfGetUnreadAndScheduledMessageCount(@inSysUserId) Data
inner join SakariContact on Data.ContactID = SakariContact.SakariContactID
inner join SakariContactOrderMap on Data.ContactID = SakariContactOrderMap.SakariContactFID
inner join Orders on SakariContactOrderMap.OrderFID = Orders.PriKey
order by LastUpdatedAt desc
end
GO
GRANT EXECUTE ON [dbo].[MssWebGetConversationListByUser] TO [MssExec]
GO