交叉应用语法

use*_*723 0 sql sql-server cross-apply

我有一个查询,我认为使用交叉申请会更有效.我已经将语法从连接更改为交叉应用,但我收到了一般语法错误:

消息170,级别15,状态1,行14行14:"应用"附近的语法不正确.Msg 156,Level 15,State 1,Line 21关键字'as'附近的语法不正确.

这是我第一次使用交叉应用,我没有看到语法错误(至少在与我发现的示例比较时).这是代码:

Select v.PC_ID
, v.PC_Name
, v.LOB
, v.REG
, v.DST
, v.PC
, d.Effective_Date as DateOfLastInc
, p.TotalPriceIncPct
, p.last_update_by
, d.PlanEffective_Date
, p2.PlanTotalPriceIncPct
--INTO #temp1
from v_PC_Profile v
cross apply (
    Select pc_id
, Effective_Date=max(Effective_Date)
, PlanEffective_Date=max(PlanEffective_Date) 
from dbo.Price_Inc_PC_Details
where pc_id = v.pc_id
group by pc_id
) as d --on d.PC_ID=v.PC_ID
left join dbo.Calendar c on c.FULL_DATE=d.Effective_Date 
left join dbo.Price_Inc_PC_Details p on d.PC_ID=p.PC_ID and d.Effective_Date=p.Effective_Date
left join dbo.Price_Inc_PC_Details p2 on d.PC_ID=p2.PC_ID and         d.PlanEffective_Date=p2.PlanEffective_Date --added by ajl 1/15/2013

WHERE segment NOT IN ('Closed', 'Overhead')
and segment not like '%closed%'
and Close_Date is NULL

group by v.PC_ID
, v.PC_Name
, v.PC
, d.Effective_Date
, p.TotalPriceIncPct
, d.PlanEffective_Date
, p2.PlanTotalPriceIncPct
, v.REG
, v.DST
, v.LOB
, p.last_update_by
, p.PlanEffective_Date
, p.PlanTotalPriceIncPct
order by v.PC_ID
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激!

SD

gbn*_*gbn 8

过去,在SQL Server的更高版本中,兼容级别为80(也称为SQL Server 2000)的数据库为UDF提供了此错误.

语法看起来没问题并在我的SQL Server 2012上解析OK.我在SQL Server 2008 R2上创建了一个数据库,其兼容性级别为80,但它也可以解析.

请参阅MSDN上的"使用APPLY"

要使用APPLY,数据库兼容级别必须至少为90.