When I run the following query, the dbo.VerySlowTableValuedFunction() gets called many times. How can I modify it so that the slow function gets called only once.
with DatesT as (
....list of dates....
), slowT as
(
select *
from dbo.VerySlowTableValuedFunction()
)
select DateS, (
select top 1 [dataseries]
from [dataseries]
where DateS = p.DateS
order by DateS desc
) as slowData
from DatesT p
There is not way to do it as of SQL Server 2008.
This has been requested as a feature… but it’s not clear it’ll be included in Denali.