SELECT
    [Id], [RunId], [TenantId], [WorkspaceId], [WorkspaceName], [MemberId], [MemberEmail], [MemberRole], [Plan], [Status], [Rule], [DeactivatedAt]
FROM [dbo].[DelinquentMemberEnforcementEvents]
WHERE (@TenantId IS NULL
   OR [TenantId] = @TenantId)
  AND (@From IS NULL
   OR [DeactivatedAt] >= @From)
  AND (@To IS NULL
   OR [DeactivatedAt] <= @To)
  AND (@Plan IS NULL
   OR [Plan] = @Plan)
  AND (@Status IS NULL
   OR [Status] = @Status)
  AND (@Rule IS NULL
   OR [Rule] = @Rule)
ORDER BY [DeactivatedAt] DESC;
