我有一个查询,我认为使用交叉应用会更有效。我已将语法从加入更改为交叉应用,但出现一般语法错误:
消息 170,级别 15,状态 1,第 14 行第 14 行:“应用”附近的语法不正确。消息 156,级别 15,状态 1,第 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
任何帮助将不胜感激!
标清