This solution is absolutely brilliant!
Here are the stats that I got on my system (compared with two other solutions):
Itzik Double Negative: CPU time = 3875 ms,...
Your last solution is really fast! It runs for about 1 second on my system. The full stats are:
Dwain Variables: CPU time = 2891 ms, elapsed time = 900 ms., logical reads...