Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- =============================================
- -- Author: Sudip Thapa
- -- Create date: 9/29/2022
- -- Description: sp to get notification count by notification type
- -- =============================================
- -- usp_GetUserNotification 49446,1,10
- CREATE PROCEDURE usp_GetUserNotification
- @UserID INT,
- @PageNo INT,
- @PageSize INT
- AS
- BEGIN
- SET NOCOUNT ON;
- DECLARE @GradeID INT;
- SELECT @GradeID = utg.GradeID
- FROM dbo.UserDetail AS ud (NOLOCK)
- INNER JOIN dbo.UserTargetGrade AS utg (NOLOCK)
- ON utg.UserTargetGradeID = ud.UserTargetGradeID
- WHERE ud.UserID = @UserID;
- SELECT COUNT(u.UserNotificationID) OVER () AS TotalCount,
- [u].[NotificationTypeID],
- u.UserNotificationID,
- u.NotificationTypeSpecificID,
- u.[Notification],
- CASE
- WHEN u.Payload IS NULL THEN
- ''
- ELSE
- u.Payload
- END AS PayLoadString
- FROM dbo.[UserNotifications] AS [u] (NOLOCK)
- INNER JOIN dbo.UserDetail AS ud (NOLOCK)
- ON ud.UserID = u.UserID
- LEFT JOIN dbo.Notices AS n (NOLOCK)
- ON n.NoticeId = u.NotificationTypeSpecificID
- AND u.NotificationTypeID = 42
- LEFT JOIN dbo.NoticeGrade AS ng (NOLOCK)
- ON ng.NoticeId = n.NoticeId
- LEFT JOIN dbo.GradeGroupGrade AS ggg (NOLOCK)
- ON ggg.GradeGroupID = ng.GradeGroupID
- AND ggg.GradeID = @GradeID
- WHERE [u].[UserID] = @UserID
- AND [u].[IsRead] = 0
- AND [u].[IsActive] = 1
- AND [u].[IsDeleted] = 0
- AND
- (
- [u].[StartDate] IS NULL
- OR [u].[StartDate] <= GETUTCDATE()
- )
- AND
- (
- n.NoticeId IS NULL
- OR
- (
- n.NoticeId > 0
- AND
- (
- ng.GradeID = @GradeID
- OR ggg.GradeGroupGradeID IS NOT NULL
- )
- )
- )
- ORDER BY u.AddedOn DESC OFFSET (@PageNo - 1) * @PageSize ROWS FETCH NEXT @PageSize ROWS ONLY;
- END;
Add Comment
Please, Sign In to add comment