>Fabio,
>Thanks for the reply. It just seem counter intuitive that the optimizer doesn't process the inner query first. Anyway I worked around it with a 2 step query using a temp table.
John,
SQL Server query optimizer doesn't take in account UDF overhead. That's why it combines both queries into one.
--sb--