So what I'm trying to attain is to count how many Users trigger EventCode 90 relative to when they last recieved a Notification.
Source tables are the following:
ServiceOne
UserNr         RegisteredUntil            NotificationMonth
532091985      2016-05-15 00:00:00.000    5
950628185      2016-03-15 00:00:00.000    3
561007126      2016-09-15 00:00:00.000    9
Notifications
UserNr         NotificationNr     NotificationDate            Service
532091985      134567             2013-04-16 00:00:00.000     1
532091985      153468             2014-04-15 00:00:00.000     1
950628185      235481             2014-02-17 00:00:00.000     1
561007126      354812             2012-08-15 00:00:00.000     1
EventLog
Time                        EventCode      UserNr
2012-12-19 00:00:00.000     90             561007126
2014-05-02 00:00:00.000     90             120456873
2009-08-24 00:00:00.000     90             935187423
The table I want is something like this:
CancMonth CancAmount
0         49091
1         53564
2         14308
What I have so far is
Select Max(datediff(month, I.NotificationDate, E.Time)  ) as CancMonth
,Count(datediff(month, I.NotificationDate, E.Time)  ) as CancAmount
From ServiceOne P, Eventlog E, Notifications N
Where P.UserNr=E.UserNr
AND P.UserNr=N.UserNr
AND E.EventCode = 90 --EventCode 90 is both flagging for deregistration and manual deregistration
AND N.Service=1
AND P.Status In (0,4) -- 0 is not registered and 4 is flagged for deregistration
AND datediff(month, N.NotificationDate, E.Time ) < 13 --Notifications are sent once a year
AND N.NotificationDate < E.Time
Group By datediff(month, N.NotificationDate, E.Time )
Order By CancMonth
I did a count on how many total records this gave and it returns about 35 000 more than I have passive and flagged users in ServiceOne.
Help is much appreciated since this has given me a massive headache the last couple of days.
EDIT: I added my source-tables and all possibly usable columns with some random sample-data
 
    