I have a query that looks like the following:
SELECT someString FROM
(
SELECT someString FROM someTable
WHERE someField = 1
) X
WHERE dbo.fnMyClrScalarFunction(X.someString) = 0
The problem is that the query optimizer is moving the UDF inside the subquery, where it is applied before the fairly restrictive 'someField = 1' condition. Unfortunately, the UDF is not exactly speedy, and this results in terrible performance. Is there any way to prevent this (aside from using a temp table) or to establish to sql server that the UDF is expensive?
Thanks in advance