I have been tasked with creating an sql script based on an OrdinalPosition, as far as I can tell my code should be working, but there is apparently an “incorrect syntax” error near the very last “ViewData.SONumber” which I am both unable to solve and unable to identify. Can someone take a look and see if there is something my brain just isn’t processing?
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
Well it appears you are missing several things with your syntax. You are missing the
ONsyntax on several of yourJOINs: