G,
your query has 2 input tables but if you check CTE it is taking input from the same table.
On the first thought, I too thought of using a function and applying it to outer query but that was degrading performance.
Regards,
Ankit
______________________________________________________________________
Ankit
MCITP Database developer SQL 2008,MCTS Database Administration SQL 2008
"Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose.
You are already naked. There is no reason not to follow your heart.”