I have encoded a representation that relies on the value of a scalar function for one if its join conditions. The query plan conservatively expects that the result of a function may change between execution when the function is constant (at least for each complete request). The result changes once a day.
Due to the large number of rows, the query plan is inefficient. I need the SQL server to know that the value will not change. Since you cannot declare a variable in the view, I am not sure how to solve the problem. Perhaps a query hint or other design will work?
We tried to code a function with a table evaluation, which did not seem to help much. This is not an ideal solution, as I would prefer to use the normal view.
Thanks Regards Craig.
source share