• It's been alluded to in the other posts but the reason why it doesn't stop is because it's a non-SARGable query and you're also thinking in terms of rows (RBAR) instead of columns.

    The problem with your original query is that it must evaluate ALL values of "N" in dateadd(month,n,'20130101') <= '20151001' because it's not evaluating by row... it's evaluating by column. This problem is the usual problem when people say that they have performance problems with a Tally or Numbers table.

    Your third query above is the correct way to do this problem.

    It seems to me that the Query Optimizer should have taken care of that problem, i.e. automatically converted the query from the one the OP originally used to the one you promote. After all the program knows everything about how it works behind the scenes, much better than we mere humans do. People might know these things on a theoretical level (or not), but we're not machines and do not (always) have the analytical capacity of one.

    Does later versions of SQL Server, for example MS SQL Server 2014, do a better job of helping in this or similar situations?