如何在公共表达式表 (CTE) 上强制执行 NOEXPAND?
当我运行以下查询时,dbo.VerySlowTableValuedFunction() 被调用多次。我该如何修改它,以便慢速函数仅被调用一次。
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 SQL Server 2008 开始还没有办法做到这一点。
这已被要求作为一项功能...但尚不清楚它是否会包含在 Denali 中。
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.