Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. SELECT * FROM (
  2. 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,
  3. M.IsDashboard, M.ClassID, M.ClassworkDay, M.PublishDateFrom, M.PublishDateTo, M.Priority, M.ReceiverType, M.SentAsMail, M.IsReadTracking, M.SentAsMobileMail, M.CancelLessonPeriodIDs,
  4. MC.CategoryName,MC.Color,
  5. DU.UserID, DU.SchoolUserID, DU.DisplayName,
  6. G.GroupID, G.GroupName, G.GroupCode, G.GroupCodeEx, G.GroupTypeID
  7. FROM Message M
  8. INNER JOIN GroupInBox GIB ON M.MessageID = GIB.MessageID
  9. INNER JOIN MessageCategory MC ON M.CategoryID = MC.CategoryID
  10. INNER JOIN DCUser DU ON M.CreatedBy = DU.UserID
  11. INNER JOIN [Group] G ON M.SenderGroupID = G.GroupID
  12. WHERE
  13. GIB.GroupID IN (SELECT GroupID FROM UserGroupReg UGR WHERE UGR.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7')
  14. AND M.PublishDateFrom <= getdate()
  15. AND M.MessageID NOT IN (SELECT MessageID FROM MessageAccessLog MAL WHERE MAL.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7' AND MAL.IsHidden=0)
  16. UNION
  17. 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,
  18. M.IsDashboard, M.ClassID, M.ClassworkDay, M.PublishDateFrom, M.PublishDateTo, M.Priority, M.ReceiverType, M.SentAsMail, M.IsReadTracking, M.SentAsMobileMail, M.CancelLessonPeriodIDs,
  19. MC.CategoryName,MC.Color,
  20. DU.UserID, DU.SchoolUserID, DU.DisplayName,
  21. G.GroupID, G.GroupName, G.GroupCode, G.GroupCodeEx, G.GroupTypeID
  22. FROM Message M
  23. INNER JOIN ProjectGroupInBox GIB ON M.MessageID = GIB.MessageID
  24. INNER JOIN MessageCategory MC ON M.CategoryID = MC.CategoryID
  25. INNER JOIN DCUser DU ON M.CreatedBy = DU.UserID
  26. INNER JOIN [Group] G ON M.SenderGroupID = G.GroupID
  27. WHERE
  28. GIB.GroupID IN (SELECT GroupID FROM UserGroupReg UGR WHERE UGR.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7')
  29. AND M.PublishDateFrom <= getdate()
  30. AND M.MessageID NOT IN (SELECT MessageID FROM MessageAccessLog MAL WHERE MAL.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7' AND MAL.IsHidden=0)
  31. UNION
  32. 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,
  33. M.IsDashboard, M.ClassID, M.ClassworkDay, M.PublishDateFrom, M.PublishDateTo, M.Priority, M.ReceiverType, M.SentAsMail, M.IsReadTracking, M.SentAsMobileMail, M.CancelLessonPeriodIDs,
  34. MC.CategoryName,MC.Color,
  35. DU.UserID, DU.SchoolUserID, DU.DisplayName,
  36. G.GroupID, G.GroupName, G.GroupCode, G.GroupCodeEx, G.GroupTypeID
  37. FROM Message M
  38. INNER JOIN PrivateInBox PIB ON M.MessageID = PIB.MessageID
  39. INNER JOIN MessageCategory MC ON M.CategoryID = MC.CategoryID
  40. INNER JOIN DCUser DU ON M.CreatedBy = DU.UserID
  41. INNER JOIN [Group] G ON M.SenderGroupID = G.GroupID
  42. WHERE
  43. PIB.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7'
  44. AND M.PublishDateFrom <= getdate()
  45. AND M.MessageID NOT IN (SELECT MessageID FROM MessageAccessLog MAL WHERE MAL.UserID = '289c416b-f0b6-4eb9-8297-76b1089134a7' AND MAL.IsHidden=0)
  46. ) AS UT
  47. WHERE
  48. (UT.IsDashboard = 1
  49. AND DATEADD(day, 1, UT.PublishDateTo) >= getdate())
  50. OR
  51. (UT.IsDashboard = 0)
  52. ORDER BY UT.UpdatedDate DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement