Always read the error message - Syntax Error, permission violation, or nonspecific Reviews another error
There is either:
An error in the sql - you can check this by running the sql in isolation.
A permission issue - harder to track, I would test this by creating a simple SSIS package and try to run it from your code.
Non specific error - eliminate the first two possibilities then look into this.
“That which can be asserted without evidence, can be dismissed without evidence.”
What's the version / localization of your SQL Server?
I tried it with SQL Server 10.0.5500, German localized Management studio. I adjusted the date format of your query, and tested it. And it worked as it was expected to work - I cannot reproduce your bug.
Msg 1823, Level 16, State 2, Line 1
A database snapshot cannot be created because it failed to start.
Msg 7928, Level 16, State 1, Line 1
The database snapshot for online checks could not be created.
Either the reason is given in a previous error or one of the underlying volumes
does not support sparse files or alternate streams. Attempting to get exclusive
access to run checks offline.
Assuming that one person can have multiple payments, an INNER JOIN will return a record for every payment over two months old, regardless of whether the person has paid within the last two months.
What you need to do is find the person records which don't have a payment record within the last two months. To do that, you can use a Not Exists filter:
DECLARE @Today date = GetUtcDate();
DECLARE @CutoffDate date = DateAdd(month, -2, @Today);
WHERE payment.national_number = person.national_number
And payment.payment_date > @CutoffDate
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer