我的任务是创建一个基于OrdinalPosition的sql脚本,据我所知,我的代码应该正常工作,但是在最后一个“ViewData.SONumber”附近显然存在“错误的语法”错误我既无法解决也无法识别。有人可以看看,看看我的大脑是否有什么东西不处理?
FROM tblReps RIGHT OUTER JOIN tblServiceOrders RIGHT OUTER JOIN dbo.tblCustomFieldDefinitions LEFT OUTER JOIN
(SELECT SONumber, [1] AS [ShippingCompany], [2] AS [Consignment_Number]
FROM (SELECT tvw_CustomSOFieldData.SONumber, tvw_CustomSOFieldData.CustomFieldValue, tvw_CustomSOFieldData.OrdinalPosition
FROM tvw_CustomSOFieldData)
PivotData PIVOT(max(CustomFieldValue) FOR OrdinalPosition IN ([1], [2])) AS CustomFieldsPivot)
AS ViewData ON tblServiceOrders.SONumber = ViewData.SONumber
答案 0 :(得分:0)
看来你的语法遗漏了几件事。您在ON
的几个问题上错过了JOIN
语法:
FROM tblReps
RIGHT OUTER JOIN tblServiceOrders
ON -- missing JOIN
RIGHT OUTER JOIN dbo.tblCustomFieldDefinitions
ON -- missing JOIN
LEFT OUTER JOIN
(
SELECT SONumber,
[1] AS [ShippingCompany],
[2] AS [Consignment_Number]
FROM
(
SELECT tvw_CustomSOFieldData.SONumber,
tvw_CustomSOFieldData.CustomFieldValue,
tvw_CustomSOFieldData.OrdinalPosition
FROM tvw_CustomSOFieldData
) PivotData
PIVOT
(
max(CustomFieldValue)
FOR OrdinalPosition IN ([1], [2])
) CustomFieldsPivot
) ViewData
ON tblServiceOrders.SONumber = ViewData.SONumber