我写了以下CTE(公用表表达式)
WITH PRODUCTION_CTE(ShortProdNo,BoatRefNumber,ProdNo, CustomerPoNumber,LoadDate, Trailer, VeadaBuilding)
AS
(
SELECT
FBS.BoatNumber AS ShortProdNo,
UOD.BoatRefNumber AS BoatRefNumber,
FBS.ProdNo AS ProdNo,
UOD.CustomerPoNumber AS CustomerPoNumber,
FBS.Shipped AS LoadDate,
FBS.TruckNum AS Trailer,
(CASE
WHEN Rtrim(UOD.CustomerPoNumber)='VEADA-VS1' THEN 'Bldg10'
ELSE 'Bldg4'
END) AS VeadaBuilding
FROM SysproCompanyV.dbo.FlatBenningtonShipping as FBS
INNER JOIN SysproCompanyV.dbo.UsrOrderDetails as UOD
ON FBS.BoatNumber=UOD.BoatRefNumber)
我从上述CTE中收到以下错误消息:
Msg 102, Level 15, State 1, Line 17
Incorrect syntax near ')'.
我不确定为什么会发生这种情况,因为CTE中允许内部联接,所有括号都已关闭并且名称已正确声明。
答案 0 :(得分:6)
您需要在声明后立即调用CTE(即PRODUCTION_CTE
):
;with PRODUCTION_CTE as (
. . .
)
select pc.*
from PRODUCTION_CTE pc