我的任务是创建一个基于 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