Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT * FROM (
- SELECT distinct M.MessageID, M.Subject, M.CategoryID, M.CreatedDate, M.CreatedBy, M.UpdatedDate, M.UpdatedBy, M.SenderGroupID, M.Tag, M.Origin, M.Item, M.NumOfSent,
- M.IsDashboard, M.ClassID, M.ClassworkDay, M.PublishDateFrom, M.PublishDateTo, M.Priority, M.ReceiverType, M.SentAsMail, M.IsReadTracking, M.SentAsMobileMail, M.CancelLessonPeriodIDs,
- MC.CategoryName,MC.Color,
- DU.UserID, DU.SchoolUserID, DU.DisplayName,
- G.GroupID, G.GroupName, G.GroupCode, G.GroupCodeEx, G.GroupTypeID
- FROM Message M
- INNER JOIN GroupInBox GIB ON M.MessageID = GIB.MessageID
- INNER JOIN MessageCategory MC ON M.CategoryID = MC.CategoryID
- INNER JOIN DCUser DU ON M.CreatedBy = DU.UserID
- INNER JOIN [Group] G ON M.SenderGroupID = G.GroupID
- WHERE
- GIB.GroupID IN (SELECT GroupID FROM UserGroupReg UGR WHERE UGR.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7')
- AND M.PublishDateFrom <= getdate()
- AND M.MessageID NOT IN (SELECT MessageID FROM MessageAccessLog MAL WHERE MAL.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7' AND MAL.IsHidden=0)
- UNION
- SELECT distinct M.MessageID, M.Subject, M.CategoryID, M.CreatedDate, M.CreatedBy, M.UpdatedDate, M.UpdatedBy, M.SenderGroupID, M.Tag, M.Origin, M.Item, M.NumOfSent,
- M.IsDashboard, M.ClassID, M.ClassworkDay, M.PublishDateFrom, M.PublishDateTo, M.Priority, M.ReceiverType, M.SentAsMail, M.IsReadTracking, M.SentAsMobileMail, M.CancelLessonPeriodIDs,
- MC.CategoryName,MC.Color,
- DU.UserID, DU.SchoolUserID, DU.DisplayName,
- G.GroupID, G.GroupName, G.GroupCode, G.GroupCodeEx, G.GroupTypeID
- FROM Message M
- INNER JOIN ProjectGroupInBox GIB ON M.MessageID = GIB.MessageID
- INNER JOIN MessageCategory MC ON M.CategoryID = MC.CategoryID
- INNER JOIN DCUser DU ON M.CreatedBy = DU.UserID
- INNER JOIN [Group] G ON M.SenderGroupID = G.GroupID
- WHERE
- GIB.GroupID IN (SELECT GroupID FROM UserGroupReg UGR WHERE UGR.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7')
- AND M.PublishDateFrom <= getdate()
- AND M.MessageID NOT IN (SELECT MessageID FROM MessageAccessLog MAL WHERE MAL.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7' AND MAL.IsHidden=0)
- UNION
- SELECT distinct M.MessageID, M.Subject, M.CategoryID, M.CreatedDate, M.CreatedBy, M.UpdatedDate, M.UpdatedBy, M.SenderGroupID, M.Tag, M.Origin, M.Item, M.NumOfSent,
- M.IsDashboard, M.ClassID, M.ClassworkDay, M.PublishDateFrom, M.PublishDateTo, M.Priority, M.ReceiverType, M.SentAsMail, M.IsReadTracking, M.SentAsMobileMail, M.CancelLessonPeriodIDs,
- MC.CategoryName,MC.Color,
- DU.UserID, DU.SchoolUserID, DU.DisplayName,
- G.GroupID, G.GroupName, G.GroupCode, G.GroupCodeEx, G.GroupTypeID
- FROM Message M
- INNER JOIN PrivateInBox PIB ON M.MessageID = PIB.MessageID
- INNER JOIN MessageCategory MC ON M.CategoryID = MC.CategoryID
- INNER JOIN DCUser DU ON M.CreatedBy = DU.UserID
- INNER JOIN [Group] G ON M.SenderGroupID = G.GroupID
- WHERE
- PIB.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7'
- AND M.PublishDateFrom <= getdate()
- AND M.MessageID NOT IN (SELECT MessageID FROM MessageAccessLog MAL WHERE MAL.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7' AND MAL.IsHidden=0)
- ) AS UT
- WHERE
- (UT.IsDashboard = 1
- AND DATEADD(day, 1, UT.PublishDateTo) >= getdate())
- OR
- (UT.IsDashboard = 0)
- ORDER BY UT.UpdatedDate DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement