Very nice indeed as it is very fast as well. I am not familiar with CTE's and Window functions, but will study this query. Yes, my initial question should have been clearer, but I think post 21 explained the requirements well enough. Thanks again for solving this. RBS